Skip to main content

Module fetch

Module fetch 

Source
Expand description

gasm:fetch for the native runner: HTTP(S) requests made for the guest (design/fetch.md).

Each request runs on a background thread (ureq, rustls with ring, the OS certificate store or SSL_CERT_FILE); the guest polls a handle, so nothing blocks a frame. Redirects are followed here, not by ureq, so every hop is checked against the host list. The body arrives in chunks through a bounded channel: a guest that stops reading pauses the download.

Headless runs can record responses (--fetch-record DIR) and replay them (--fetch-replay DIR): a replayed request completes at the start of the next frame, on every runner, so hashes compare. The record format and key are shared with runners/web/lib/fetch.js.

Structs§

Desc
A request the guest described (validated).
Fetch

Enums§

FetchMode
Where responses come from.

Constants§

DONE
FAILED
FORBIDDEN_HEADERS
Request headers browsers don’t let pages set (the Fetch standard’s forbidden request headers, plus user-agent): a request with one fails on every runner, so a game can’t come to depend on it. Same list in runners/web/lib/fetch.js.
FORBIDDEN_PREFIXES
HEADERS
HIDDEN_RESPONSE_HEADERS
Response headers no runner reports: connection-level ones (browsers’ fetch() hides them or they differ by HTTP version) and cookies (fetch() never exposes them). Same list in runners/web/lib/fetch.js.
MAX_BODY
Largest response body; a larger one fails the request.
MAX_REQUESTS
MAX_REQUEST_BODY
METHODS
PENDING

Functions§

header_lines
Response headers as the guest sees them, the way fetch()’s Headers lists them: name: value lines sorted by (lowercase) name, repeated names joined with “, “. The body the guest reads is always decoded (gzip natively; browsers decode everything), so content-encoding is left out, and content-length too when it counted encoded bytes.
parse_desc
Parse and check a request description; Err says why it’s refused.
record_key
FNV-1a 64 of method, URL and body: the name of a recorded response.
resolve_url
location relative to base (absolute, origin-relative, or path-relative).
user_agent
gasm-run/<version>, after the game’s own identity if it has one (--app-id "mygame/1.2 (+https://mygame.example)").
valid_app_id
Whether id can go into a User-Agent header: printable ASCII, 1 to 256 characters.