Net
HTTP, off the caller’s thread. Each host it talks to, redirects too, has to be in “permissions”: { “net”: […] } in its wraith.json.
Get it with Api.net().
fetch(request: import("salamander").Given<Wraith.Net.Request>): Promise<Wraith.Net.Response>download(request: import("salamander").Given<Wraith.Net.Request>, path: string): Promise<bigint>downloading(path: string): Wraith.Net.Progressfetch(request: Wraith.Net.Request): salamander.Promisedownload(request: Wraith.Net.Request, path: string): salamander.Promisedownloading(path: string): Wraith.Net.ProgressSystem.Threading.Tasks.Task<Wraith.Net.Response> FetchAsync(Wraith.Net.Request request, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task<ulong> DownloadAsync(Wraith.Net.Request request, string path, System.Threading.CancellationToken cancel = default)Wraith.Net.Progress Downloading(string path)sal::Future<Wraith::Net_Response, Wraith::NetError> fetch(Wraith::Net_Request request) constsal::Future<uint64_t, Wraith::NetError> download(Wraith::Net_Request request, std::string_view path) constWraith::Net_Progress downloading(std::string_view path) constpub fn fetch(&self, request: wraith::NetRequest) -> salamander::Future<wraith::NetResponse, wraith::NetError>pub fn download(&self, request: wraith::NetRequest, path: &str) -> salamander::Future<u64, wraith::NetError>pub fn downloading(&self, path: &str) -> wraith::NetProgressfn fetch(self: Wraith.Net, request: raw.Wraith_Net_Request) rt.Promise((Wraith.NetError || rt.Failure)!raw.Wraith_Net_Response, Wraith.NetErrorCode)fn download(self: Wraith.Net, request: raw.Wraith_Net_Request, path: []const u8) rt.Promise((Wraith.NetError || rt.Failure)!u64, Wraith.NetErrorCode)fn downloading(self: Wraith.Net, path: []const u8) Wraith.Net.Progresssal_Promise Wraith_Net_fetch(Wraith_Net self, Wraith_Net_Request request)sal_Promise Wraith_Net_download(Wraith_Net self, Wraith_Net_Request request, sal_string path)Wraith_Net_Progress Wraith_Net_downloading(Wraith_Net self, sal_string path)Settles with any status, so check it. Follows up to 5 redirects.
Async. Fails with NetError. Uses Net.Request, Net.Response.
download
Section titled “download”Streams the body to path, replacing what’s there once it’s all in, and settles with its size.
Relative paths are in its folder for this game.
Async. Fails with NetError. Uses Net.Request.
downloading
Section titled “downloading”How its download to path is going, for drawing progress. Any thread.
Uses Net.Progress.
NetError
Section titled “NetError”What can go wrong, besides Cancelled, Unsupported and Gone.
| Code | Error | |
|---|---|---|
| 1 | Failed |
Couldn’t connect, or the connection broke |
| 2 | NotDeclared |
Its host, or one it redirects to, isn’t in “permissions”: { “net”: […] } |
| 3 | InvalidUrl |
Not an http:// or https:// URL |
| 4 | TooBig |
Longer than max_bytes |
| 5 | Status |
For download, when the server says no, like 404. fetch gives the status instead |
| 6 | WriteFailed |
For download: couldn’t write there, or it’s outside its folders without “files” |
| 7 | Timeout |
Nothing arrived for timeout_ms |
Net.Method
Section titled “Net.Method”An enum of u8.
| Value | Name | |
|---|---|---|
| 0 | get |
|
| 1 | head |
|
| 2 | post |
|
| 3 | put |
|
| 4 | patch |
|
| 5 | delete |
Net.Header
Section titled “Net.Header”A struct, 0x20 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | name |
string |
|
| 0x10 | value |
string |
name: stringvalue: stringname: stringvalue: stringstring Namestring Valuesal::String namesal::String valuepub name: salamander::Strpub value: salamander::Strname: []const u8value: []const u8sal_string namesal_string valueNet.Request
Section titled “Net.Request”A struct, 0x48 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | url |
string |
|
| 0x10 | method |
Net.Method |
|
| 0x18 | headers |
[]Net.Header |
|
| 0x28 | body |
[]u8 |
Sent with a content-length, for post, put and patch |
| 0x38 | max_bytes |
u64 |
0 for the most fetch keeps, 64 MiB. Downloads have no limit unless they say |
| 0x40 | timeout_ms |
u32 |
How long it waits with nothing arriving, so a slow download still finishes. 0 for 30 s |
url: stringmethod: Wraith.Net.Method | Wraith.Net.MethodNameheaders: Array<Wraith.Net.Header>body: Array<number>max_bytes: biginttimeout_ms: numberurl: stringmethod: Wraith.Net.Method|Wraith.Net.MethodNameheaders: (Wraith.Net.Header)[]body: (integer)[]max_bytes: integertimeout_ms: integerstring UrlWraith.Net.Method MethodWraith.Net.Header[] Headersbyte[] Bodyulong MaxBytesuint TimeoutMssal::String urlWraith::Net_Method methodsal::Slice<Wraith::Net_Header> headerssal::Slice<uint8_t> bodyuint64_t max_bytesuint32_t timeout_mspub url: salamander::Strpub method: wraith::NetMethodpub headers: salamander::Slice<wraith::NetHeader>pub body: salamander::Slice<u8>pub max_bytes: u64pub timeout_ms: u32url: []const u8method: Wraith.Net.Methodheaders: []const Wraith.Net.Headerbody: []const u8max_bytes: u64timeout_ms: u32sal_string urlWraith_Net_Method methodSlice_Wraith_Net_Header headersSlice_u8 bodyuint64_t max_bytesuint32_t timeout_msNet.Response
Section titled “Net.Response”A struct, 0x28 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | status |
u16 |
|
| 0x8 | headers |
[]Net.Header |
|
| 0x18 | body |
blob |
status: numberheaders: Array<Wraith.Net.Header>body: Uint8Array | nullstatus: integerheaders: (Wraith.Net.Header)[]body: stringushort StatusWraith.Net.Header[] HeadersSalamander.Blob? Bodyuint16_t statussal::Slice<Wraith::Net_Header> headerssal::Blob bodypub status: u16pub headers: salamander::Slice<wraith::NetHeader>pub body: salamander::Blobstatus: u16headers: []const Wraith.Net.Headerbody: rt.Blobuint16_t statusSlice_Wraith_Net_Header headerssal_object bodyNet.Progress
Section titled “Net.Progress”A struct, 0x18 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | received |
u64 |
|
| 0x8 | total |
u64 |
0 if the server didn’t say |
| 0x10 | active |
bool |
False before it starts and once it’s done |
received: biginttotal: bigintactive: booleanreceived: integertotal: integeractive: booleanulong Receivedulong TotalSalamander.Bool Activeuint64_t receiveduint64_t totalbool activepub received: u64pub total: u64pub active: boolreceived: u64total: u64active: booluint64_t receiveduint64_t totalbool activewraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
