Skip to main content

Crate modkit_http

Crate modkit_http 

Source
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, deflate header on all requests
  • Decompresses response bodies based on Content-Encoding header
  • 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§

otel
OpenTelemetry trace context helpers for HTTP headers
security
HTTP security utilities.

Structs§

ExponentialBackoff
Exponential backoff configuration for retries
HttpClient
HTTP client with tower middleware stack
HttpClientBuilder
Builder for constructing an [HttpClient] with a layered tower middleware stack.
HttpClientConfig
Overall HTTP client configuration
HttpResponse
HTTP response wrapper with body-reading helpers
LimitedBody
Body wrapper that enforces size limits during streaming.
OtelLayer
Tower layer that adds OpenTelemetry tracing to outbound HTTP requests
OtelService
Service that wraps requests with OpenTelemetry tracing spans
RateLimitConfig
Rate limiting / concurrency limit configuration
RedirectConfig
Configuration for redirect behavior
RequestBuilder
HTTP request builder with fluent API
RetryConfig
Retry policy configuration with exponential backoff
RetryLayer
Tower layer that implements retry with exponential backoff and jitter
RetryService
Service that implements retry logic with exponential backoff
SecureRedirectPolicy
A security-hardened redirect policy
UserAgentLayer
Tower layer that adds User-Agent header to all requests
UserAgentService
Service that adds User-Agent header to requests

Enums§

HttpError
HTTP client error types
InvalidUriKind
Classification of URL validation failures.
RetryTrigger
Conditions that trigger a retry
TlsRootConfig
TLS root certificate configuration
TransportSecurity
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§

ResponseBody
Type alias for the boxed response body that supports decompression.