Expand description
HTTP client infrastructure for ToolKit
This crate provides a hyper-based HTTP client with:
- Automatic TLS via rustls; transport security is configurable via
TransportSecurity— defaults toTlsOnly(HTTPS-only) under--features fips,AllowInsecureHttpotherwise - Connection pooling
- Configurable timeouts
- Automatic retries with exponential backoff
- User-Agent header injection
- Concurrency limiting
- Transparent response decompression (gzip, brotli, deflate)
- Optional OpenTelemetry tracing (feature-gated)
§Transparent Decompression
The client automatically:
- Sends
Accept-Encoding: gzip, br, deflateheader on all requests - Decompresses response bodies based on
Content-Encodingheader - Applies body size limits to decompressed bytes (protecting against zip bombs)
No configuration is required; decompression is always enabled.
§Example
ⓘ
use toolkit_http::{HttpClient, HttpClientBuilder};
use std::time::Duration;
let client = HttpClient::builder()
.timeout(Duration::from_secs(10))
.user_agent("my-app/1.0")
.build()?;
// reqwest-like API: response has body-reading methods
// Compressed responses are automatically decompressed
let data: MyData = client
.get("https://example.com/api")
.send()
.await?
.json()
.await?;Re-exports§
pub use security::attach_bearer_http;pub use security::attach_internal_token_http;
Modules§
Structs§
- Client
Auth Config - TLS building blocks shared with other transport crates (e.g. the upstream
proxy engine) so every outbound
ClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. Client-certificate (mutual TLS) identity. - Exponential
Backoff - Exponential backoff configuration for retries
- Http
Client - HTTP client with tower middleware stack
- Http
Client Builder - Builder for constructing an [
HttpClient] with a layered tower middleware stack. - Http
Client Config - Overall HTTP client configuration
- Http
Response - HTTP response wrapper with body-reading helpers
- Limited
Body - Body wrapper that enforces size limits during streaming.
- Metrics
Layer - Tower layer recording HTTP client request-duration metrics.
- Metrics
Service - Service that records a duration metric for each outbound request.
- Otel
Layer - Tower layer that adds OpenTelemetry tracing to outbound HTTP requests
- Otel
Service - Service that wraps requests with OpenTelemetry tracing spans
- Rate
Limit Config - Concurrency-limit configuration.
- Redirect
Config - Configuration for redirect behavior
- Request
Builder - HTTP request builder with fluent API
- Request
Type - Per-request label for the
request_typemetrics attribute. - Retry
Config - Retry policy configuration with exponential backoff
- Retry
Layer - Tower layer that implements retry with exponential backoff and jitter
- Retry
Service - Service that implements retry logic with exponential backoff
- Secure
Redirect Policy - A security-hardened redirect policy
- TlsConfig
- TLS building blocks shared with other transport crates (e.g. the upstream
proxy engine) so every outbound
ClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. TLS handshake configuration for the HTTP client. - User
Agent Layer - Tower layer that adds User-Agent header to all requests
- User
Agent Service - Service that adds User-Agent header to requests
Enums§
- Http
Error - HTTP client error types
- Invalid
UriKind - Classification of URL validation failures.
- Retry
Trigger - Conditions that trigger a retry
- TlsConfig
Error - Error type returned by the fallible TLS-config builders in this gear.
- TlsRoot
Config - TLS root certificate configuration
- TlsVersion
- TLS building blocks shared with other transport crates (e.g. the upstream
proxy engine) so every outbound
ClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. TLS building blocks shared with other transport crates (e.g. the upstream proxy engine) so every outboundClientConfiggoes through the same provider selection and FIPS hardening. Minimum TLS protocol version the client will negotiate. - Transport
Security - Transport security configuration
Constants§
- DEFAULT_
USER_ AGENT - Default User-Agent string for HTTP requests
- IDEMPOTENCY_
KEY_ HEADER - Standard idempotency key header name (display form)
- RETRY_
ATTEMPT_ HEADER - Header name for retry attempt number (1-indexed). Added to retried requests to indicate which retry attempt this is.
Functions§
- custom_
roots_ client_ config - Build a rustls
ClientConfigtrusting exactlyroot_store(e.g. a private CA for internal upstreams). - default_
classify - Default classifier producing
"METHOD host"(mirrors go-appkit’s defaultsummary). Never returns a raw path, so it cannot blow up cardinality. - is_
idempotent_ method - Check if HTTP method is idempotent (safe to retry) per RFC 9110.
- native_
roots_ client_ config - Build a rustls
ClientConfigusing the cached native root certificates. - webpki_
roots_ client_ config - Build a rustls
ClientConfigusing Mozilla’s webpki-roots trust anchors.
Type Aliases§
- Classify
Fn - Classifies a request into a low-cardinality route label (the
http.routeattribute). Set once when the client is built; invoked on every request. - Response
Body - Type alias for the boxed response body that supports decompression.