Skip to main content

Module http

Module http 

Source
Expand description

Unified outbound HTTP client.

Every provider/API call in the workspace should eventually go through HttpClient so that timeout, retry, body-size and cancellation policies are defined in one place instead of drifting across 20 crates.

§Policies

  • Two profiles: Profile::Api (connect 10s, total 60s, body capped at 10 MiB) and Profile::Sse (connect 10s, total 300s, response body is streamed, not buffered).
  • Retries are attempted only for statuses 408/429/500/502/503/504 and for connection/timeout transport errors. 501 and 505 are returned immediately — retrying a “not implemented”/“version unsupported” response just hammers a server that can never succeed.
  • Retry-After is honored in both its forms (delta-seconds and IMF-fixdate, per RFC 9110) and is never truncated by the backoff cap.
  • Backoff uses full jitter; retry sleeps are cancellation-aware.
  • For SSE, retries happen only while establishing the stream (before the first successful response). A stream that breaks mid-flight is not reconnected, because that would silently replay already-delivered events.

§SSRF

This client is for public provider endpoints and does not perform private-address pinning. Callers that fetch user-supplied URLs (tools, web loaders) must keep using crate::ssrf::guarded_get and friends.

Structs§

BoundedResponse
A fully buffered response with status and headers.
HttpClient
A configured outbound HTTP client. Cheap to clone (wraps an Arc’d pool).
HttpClientBuilder
Builder for HttpClient. Construct via HttpClient::api / HttpClient::sse or HttpClient::builder.
RequestOptions
Per-request overrides applied on top of the client defaults.
RetryPolicy
Retry policy: attempt count, backoff bounds and transport classification.

Enums§

HttpError
Errors produced by the unified HTTP layer.
Profile
Selects the built-in timeout/body profile.
TransportRetryMode
Which transport errors are eligible for retry.

Constants§

DEFAULT_API_MAX_BYTES
Default response body cap for API calls: 10 MiB.
DEFAULT_API_TOTAL_TIMEOUT
Default total (connect + send + response headers) budget for API calls.
DEFAULT_CONNECT_TIMEOUT
Default TCP connect timeout for both profiles.
DEFAULT_SSE_TOTAL_TIMEOUT
Default total budget for establishing an SSE stream.
ERROR_BODY_BYTES
Upper bound read from an error response body so messages stay bounded.

Functions§

compute_backoff
Full-jitter backoff: uniform in [0, min(base * 2^attempt, max_delay)].
is_retryable_status
Returns true for the closed set of retriable statuses: 408, 429, 500, 502, 503, 504. Notably 501/505 are NOT retriable.
normalize_base_url
Canonical base-URL normalization used by every provider config.
parse_retry_after
Parses a Retry-After header, accepting both delta-seconds and an IMF-fixdate. A date in the past resolves to Duration::ZERO.

Type Aliases§

SseStream
Boxed SSE byte stream.