Expand description
HTTP client infrastructure for ModKit
This crate provides a hyper-based HTTP client with:
- Automatic TLS via rustls (HTTPS only by default)
- 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 modkit_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?;Modules§
Structs§
- 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.
- 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 - Rate limiting / concurrency limit configuration
- Redirect
Config - Configuration for redirect behavior
- Request
Builder - HTTP request builder with fluent API
- 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
- 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
- TlsRoot
Config - TLS root certificate configuration
- 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§
- is_
idempotent_ method - Check if HTTP method is idempotent (safe to retry) per RFC 9110.
Type Aliases§
- Response
Body - Type alias for the boxed response body that supports decompression.