Skip to main content

Module http_fetch

Module http_fetch 

Source
Expand description

The HTTP round trip the HTTP-family clients share: reqwest natively, hyper’s HTTP/1.1 client over the virtual loopback in the browser build. The HTTP round trip the HTTP-family clients share, on both targets.

Natively a FetchClient wraps the reqwest::Client each protocol already builds (its own timeout, the literal-IP resolver bypass, its connection pool), and every call is reqwest’s own: what goes on the wire is exactly what reqwest sends. In the browser build reqwest cannot serve (its wasm backend is the browser’s fetch, which is not Send and cannot reach the page’s virtual loopback), so the same calls go through transport — hyper’s HTTP/1.1 client over tokio::net::TcpStream, which on wasm32 is crates/netget-tokio-wasm’s virtual network. The client logic above the round trip is one copy.

The API is the subset of reqwest’s the clients use — get/post/…, header, query, json, form, body, basic_auth, timeout, send, and on the response status, headers, text, json, bytes, chunk — so converting a client is a type change, not a rewrite.

The transport backend is also constructible natively (FetchClient::transport), which is how tests/client/http/fetch_client_test.rs pins it down without a browser.

Differences on the transport, stated: no TLS (https:// is refused with transport::HTTPS_UNSUPPORTED — call check_url where a client takes its target so the refusal comes at connect rather than on the first request), no redirects, one connection per request, and the whole response body is read up front against FetchClient’s body bound (8 MiB unless FetchClient::with_max_body says otherwise), so chunk() yields it once.

Modules§

transport
One HTTP/1.1 request and its response, over a stream NetGet opens itself.

Structs§

FetchClient
An HTTP client: reqwest natively, transport in the browser (or wherever FetchClient::transport is asked for).
FetchError
A FetchClient failure as a std::error::Error, for crates whose HTTP hook requires one (oauth2’s and openidconnect’s request_async / discover_async).
FetchRequest
One request being built. Errors in a header or a body are held until Self::send, as reqwest’s builder does.
FetchResponse
A response. Natively reqwest’s, streamed as reqwest streams it; on the transport already read in full (bounded), so chunk yields the whole body once.

Functions§

check_url
Refuse a target the browser transport cannot reach, with the reason; natively every URL reqwest accepts is accepted. Call it where a client takes its base URL, so an https:// target in the browser fails at connect, naming why, rather than on its first request.
origin_of
scheme://host[:port] of url, host lowercased and a default port dropped, so two spellings of one origin compare equal and two origins never do.
read_response_bytes
Read a native buffered response without trusting Content-Length. Streaming callers use chunk() directly; buffered model events have a byte cap and whole-read deadline.
read_response_json
Parse JSON only after the complete response meets the byte and time bounds.
read_response_text
Read bounded text while preserving reqwest’s Content-Type charset/BOM decoding.
resolve_same_origin
Resolve an action’s path against the client’s base URL, refusing any other origin.
round_trip_parts
One request given as raw parts, for a crate’s own HTTP hook to call: the method, the URL, the headers as (name, value bytes) and the body, back as the status, the headers and the body. Header values that are not visible ASCII are sent lossily; the hooks that call this (OAuth2 and OpenID Connect token, discovery and key-set requests) send none.
same_origin_redirects
A redirect policy that follows up to five hops, none of them to another origin.