Expand description
A WHATWG fetch + Headers + Request + Response, so code that
expects fetch works. It is a thin surface over the ferrijs-fetch
engine, reached through a FetchBackend the host chooses — one
HTTP stack, one place the net policy applies.
Web-standard names: Headers, Request, Response are the WHATWG
classes. Headers is spec (lowercase + RFC7230 validate, value
normalize, , combine, separate set-cookie + getSetCookie,
sorted real iterators, forEach). Response / Request are
constructible with the spec accessors (status/ok/redirected/
type/bodyUsed/headers/…), single-use bodies
(text/json/arrayBuffer), clone(), and static
Response.json/error/redirect. fetch(url, { signal }) is wired
to AbortController/AbortSignal (see abort): an already-aborted
signal rejects before I/O and an in-flight abort drops the request
future. Response.body is a WHATWG ReadableStream that pulls
chunks live off the socket (the body is NOT buffered) — the same
stream object on every access, drained by text()/json()/
arrayBuffer(), and pipeable through a TransformStream into a
WritableStream. clone() tees it, so both responses read the full
payload off one socket even when nothing has been buffered yet. See
streams.
Bodies: fetch(url, { body }), new Request(input, { body }) and
new Response(body) all take the same BodyInit union, so all three
go through the one “extract a body” step in body_init — never
their own subset of the union. Headers is likewise a view over the
engine’s ferrijs_fetch::Headers list, so the JS class and the
Rust client share one set of header semantics.
Net policy: fetch hands the realm’s container to the engine as the
request’s NetGuard, which checks the initial URL and every
redirect hop against it. The container only ever narrows, so a check
made later in the request is never looser than one made at the call.
A refusal is thrown as the PermissionDeniedError it is.
Re-exports§
pub use backend::Client;pub use backend::FetchBackend;pub use backend::FetchFuture;pub use backend::FetchRequest;pub use ferrijs_fetch as engine;
Modules§
- abort
- Runtime-side glue over the vendored WHATWG
AbortController/AbortSignal(ferrijs_std::abort). - backend
- What the
fetchglobal sends through. - body_
init - The WHATWG “extract a body” step (Fetch §7.4), in one place.
- multipart
- The bridge between the JS
FormDataclass and the core multipart wire types. - streams
- Native underlying sources for the vendored WHATWG
ReadableStream(ferrijs_std::stream_web).
Structs§
- Fetch
Extension - The realm’s
fetchas ancrate::Extension, overbackend. - Fetch
Request Js - WHATWG
Request(spec subset). Constructible (new Request(input, init?)whereinputis a URL string or anotherRequest), withurl/method/headers/redirect/credentials/bodyUsedaccessors andtext/json/arrayBuffer/clone. Asignalpassed ininitis carried (as the native abort channel) and forwarded byfetch(request);fetchreadsurl/method/headers/body/redirect/credentials/signaloff aRequestargument. - Fetch
Response Js - WHATWG
Response(spec subset). Constructible (new Response(body?, init?)), withstatus/ok/statusText/url/redirected/type/bodyUsed/headersaccessors,text/json/arrayBufferbody readers (single-use: a second read throws, per spec),clone()(throws once the body is used), and staticResponse.json,Response.error,Response.redirect. This is the globalResponse(the Playwright page-networkResponseis no longer a global — it is only ever a return value, matching Playwright itself). - Headers
Js - WHATWG
Headers, a view over the coreferrijs_fetch::Headerslist: names are lowercased and RFC7230-validated, values are HTTP-whitespace normalized and validated,appendcombines same-name values with,whileset-cookieis kept as separate entries,getSetCookie()returns them all, and iteration is sorted by name. The list semantics live in core (fetch::headers) so this class and the Rust HTTP client cannot drift; only the JS surface is here.keys/values/entries/[Symbol.iterator]return real iterator objects.
Functions§
- define_
classes - Define the
Headers/Request/Responseclasses onglobalThis. Idempotent per realm;installcalls it. - function
- A
fetchfunction overbackend, not installed anywhere: for a host handing a caller an attenuated capability rather than the global. - install
- Install
globalThis.fetchoverbackend, with the classes it speaks. A realm’snetgrant applies to every request it sends.