Skip to main content

Module http

Module http 

Source
Expand description

A small injectable HTTP client abstraction shared by the registry lookup, the ecosystem resolvers, and (later) the web/llms-txt sources.

The TypeScript code calls the global fetch; porting that verbatim would make every network path untestable without a live server. Instead callers take a &dyn HttpClient, so production wires UreqClient (a 10s-timeout ureq agent) while tests inject [mock::MockClient] with canned responses — the same parity-by-unit-test approach used for the pure modules.

Structs§

BytesResponse
A completed HTTP response with a binary body (for archive downloads).
HttpResponse
A completed HTTP response: the numeric status and the body as text. Non-2xx responses are returned as Ok (not errors) so callers can branch on 404 vs other statuses exactly like the TS response.ok / response.status checks.
UreqClient
The production client: a ureq agent with a 10s global timeout (parity with the TS AbortSignal.timeout(10_000)) that surfaces HTTP status codes rather than turning 4xx/5xx into transport errors.

Traits§

HttpClient
A GET-only HTTP client. get reads the body as text; get_bytes reads it as raw bytes with optional request headers (used for GitHub/npm tarball downloads). A transport failure (DNS, connect, timeout, read) is an Err, while any HTTP status (including 4xx/5xx) is an Ok.

Functions§

encode_uri_component
Percent-encode a string the way JavaScript’s encodeURIComponent does: everything except the unreserved set A-Za-z0-9-_.!~*'() is UTF-8 encoded to %XX (uppercase hex). Used for registry catch-all path segments (scoped npm names contain / and @) and Maven Solr query params.