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§
- Bytes
Response - A completed HTTP response with a binary body (for archive downloads).
- Http
Response - 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 TSresponse.ok/response.statuschecks. - Ureq
Client - 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§
- Http
Client - A GET-only HTTP client.
getreads the body as text;get_bytesreads it as raw bytes with optional request headers (used for GitHub/npm tarball downloads). A transport failure (DNS, connect, timeout, read) is anErr, while any HTTP status (including 4xx/5xx) is anOk.
Functions§
- encode_
uri_ component - Percent-encode a string the way JavaScript’s
encodeURIComponentdoes: everything except the unreserved setA-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.