Wren a web browser where WebAssembly runs everything, JavaScript included

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.

membervalue
Pending0
Response1
Done2
Failed3

enum ResponseType : i32

Response.type

membervalue
Basic0
Cors1
Opaque2
Opaque_Redirect3

enum FetchMode : u32

RequestInit.mode

membervalue
Cors0
Same_Origin1
No_Cors2

enum Credentials : u32

RequestInit.credentials

membervalue
Same_Origin0
Omit1
Include2

enum RedirectMode : u32

RequestInit.redirect

membervalue
Follow0
Error1
Manual2

enum ReferrerPolicy : u32

RequestInit.referrerPolicy (Default: the document's policy).

membervalue
Default0
No_Referrer1
No_Referrer_When_Downgrade2
Same_Origin3
Origin4
Strict_Origin5
Origin_When_Cross_Origin6
Strict_Origin_When_Cross_Origin7
Unsafe_Url8

enum RequestCache : u32

RequestInit.cache: how the request uses the browser's HTTP cache (Fetch Standard cache modes).

membervalue
Default0
No_Store1
Reload2
No_Cache3
Force_Cache4
Only_If_Cached5

struct FetchOptions

RequestInit beyond method, headers and body. The zero value is the Fetch API default.

fieldtype
modeFetchMode
credentialsCredentials
redirectRedirectMode
referrer_policyReferrerPolicy
no_referrerboolreferrer: "" (send none).
cacheRequestCacheonly-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) raises

Cancels 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

Edit this page on GitHub