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§
- Fetch
Client - An HTTP client: reqwest natively,
transportin the browser (or whereverFetchClient::transportis asked for). - Fetch
Error - A
FetchClientfailure as astd::error::Error, for crates whose HTTP hook requires one (oauth2’s and openidconnect’srequest_async/discover_async). - Fetch
Request - One request being built. Errors in a header or a body are held until
Self::send, as reqwest’s builder does. - Fetch
Response - A response. Natively reqwest’s, streamed as reqwest streams it; on the transport already
read in full (bounded), so
chunkyields 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]ofurl, 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
pathagainst 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.