Module net
Fetch with a callback (Fetch Standard through the browser's loader: origin, CORS, cookies, referrer, CSP and mixed content are the browser's business, never the module's). The callback learns each step; the response is read from the request record until Fetch_release. A Response (module fetch) is the same record.
Exposed to: Window, Worker. Source: api/net.widl.
Odin: import "wren:net".
Types
handle Fetch
A request and, once it arrived, its response.
Checked by the browser on every call (lookup_Fetch).
handle Response : Fetch
The response of a fetch (what Fetch_promise settles with): the same record as its Fetch.
enum FetchState : i32
Where a request is.
| member | value | |
|---|---|---|
Pending | 0 | |
Response | 1 | |
Done | 2 | |
Failed | 3 |
enum ResponseType : i32
Response.type
| member | value | |
|---|---|---|
Basic | 0 | |
Cors | 1 | |
Opaque | 2 | |
Opaque_Redirect | 3 |
enum FetchMode : u32
RequestInit.mode
| member | value | |
|---|---|---|
Cors | 0 | |
Same_Origin | 1 | |
No_Cors | 2 |
enum Credentials : u32
RequestInit.credentials
| member | value | |
|---|---|---|
Same_Origin | 0 | |
Omit | 1 | |
Include | 2 |
enum RedirectMode : u32
RequestInit.redirect
| member | value | |
|---|---|---|
Follow | 0 | |
Error | 1 | |
Manual | 2 |
enum ReferrerPolicy : u32
RequestInit.referrerPolicy (Default: the document's policy).
| member | value | |
|---|---|---|
Default | 0 | |
No_Referrer | 1 | |
No_Referrer_When_Downgrade | 2 | |
Same_Origin | 3 | |
Origin | 4 | |
Strict_Origin | 5 | |
Origin_When_Cross_Origin | 6 | |
Strict_Origin_When_Cross_Origin | 7 | |
Unsafe_Url | 8 |
enum RequestCache : u32
RequestInit.cache: how the request uses the browser's HTTP cache (Fetch Standard cache modes).
| member | value | |
|---|---|---|
Default | 0 | |
No_Store | 1 | |
Reload | 2 | |
No_Cache | 3 | |
Force_Cache | 4 | |
Only_If_Cached | 5 |
struct FetchOptions
RequestInit beyond method, headers and body. The zero value is the Fetch API default.
| field | type | |
|---|---|---|
mode | FetchMode | |
credentials | Credentials | |
redirect | RedirectMode | |
referrer_policy | ReferrerPolicy | |
no_referrer | bool | referrer: "" (send none). |
cache | RequestCache | only-if-cached needs mode Same_Origin. |
callback FetchCallback
void FetchCallback(i32 user, Fetch request, FetchState state)Called when the response arrives (Response), when the body is complete (Done) or on failure (Failed).
Functions
Fetch_start
Fetch Fetch_start(string url, FetchCallback callback, i32 user = 0, string method = "GET", string headers = "", optional bytes body, FetchOptions options = none)fetch(url, {method, headers, body, ...}) with a callback. headers are "Name: value" lines (CR LF or LF). A
relative URL resolves against the document (or the worker's script).
Host: Fetch_start :: proc(c: ^Call, url: string, callback: u32, user: i32, method: string, headers: string, body: Maybe([]u8), options: Api_FetchOptions) -> u64
Fetch_state
FetchState Fetch_state(Fetch request)Host: Fetch_state :: proc(c: ^Call, request: Api_Fetch) -> Api_FetchState
Fetch_status
i32 Fetch_status(Fetch request)The HTTP status (0 for an opaque response).
Host: Fetch_status :: proc(c: ^Call, request: Api_Fetch) -> i32
Fetch_type
ResponseType Fetch_type(Fetch request)Host: Fetch_type :: proc(c: ^Call, request: Api_Fetch) -> Api_ResponseType
Fetch_redirected
bool Fetch_redirected(Fetch request)Host: Fetch_redirected :: proc(c: ^Call, request: Api_Fetch) -> bool
Fetch_headers
string Fetch_headers(Fetch request)The response headers the module may see: "Name: value" lines, CR LF terminated.
Host: Fetch_headers :: proc(c: ^Call, request: Api_Fetch) -> string
Fetch_url
string Fetch_url(Fetch request)The final URL (after redirects).
Host: Fetch_url :: proc(c: ^Call, request: Api_Fetch) -> string
Fetch_error
string Fetch_error(Fetch request)Why it failed ("" before a failure).
Host: Fetch_error :: proc(c: ^Call, request: Api_Fetch) -> string
Fetch_errorKind
i32 Fetch_errorKind(Fetch request)The fetch.Error_Kind of a failure (0 none, then Bad_URL, Bad_Scheme... in the browser's order).
Host: Fetch_errorKind :: proc(c: ^Call, request: Api_Fetch) -> i32
Fetch_bodyLength
u64 Fetch_bodyLength(Fetch request)The bytes of the body received so far.
Host: Fetch_bodyLength :: proc(c: ^Call, request: Api_Fetch) -> u64
Fetch_readBody
i32 Fetch_readBody(Fetch request, u64 offset, out bytes buffer)Copies the body from offset into buffer; returns how many bytes were copied.
Host: Fetch_readBody :: proc(c: ^Call, request: Api_Fetch, offset: u64, buffer: []u8) -> i32
Fetch_release
void Fetch_release(Fetch request) raisesCancels the request if needed and frees the record.
Raises: returns an Error (see web).
Host: Fetch_release :: proc(c: ^Call, request: Api_Fetch) -> Api_Error