Skip to main content

toolkit_http/
lib.rs

1#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
2#![warn(warnings)]
3
4//! HTTP client infrastructure for `ToolKit`
5//!
6//! This crate provides a hyper-based HTTP client with:
7//! - Automatic TLS via rustls; transport security is configurable via
8//!   [`TransportSecurity`] — defaults to
9//!   `TlsOnly` (HTTPS-only) under `--features fips`, `AllowInsecureHttp` otherwise;
10//!   under `fips`, plaintext is an explicit opt-in that logs a warning
11//! - Connection pooling
12//! - Configurable timeouts
13//! - Automatic retries with exponential backoff
14//! - User-Agent header injection
15//! - Concurrency limiting
16//! - **Transparent response decompression** (gzip, brotli, deflate)
17//! - Optional OpenTelemetry tracing (feature-gated)
18//!
19//! # Transparent Decompression
20//!
21//! The client automatically:
22//! - Sends `Accept-Encoding: gzip, br, deflate` header on all requests
23//! - Decompresses response bodies based on `Content-Encoding` header
24//! - Applies body size limits to **decompressed** bytes (protecting against zip bombs)
25//!
26//! No configuration is required; decompression is always enabled.
27//!
28//! # Example
29//!
30//! ```ignore
31//! use toolkit_http::{HttpClient, HttpClientBuilder};
32//! use std::time::Duration;
33//!
34//! let client = HttpClient::builder()
35//!     .timeout(Duration::from_secs(10))
36//!     .user_agent("my-app/1.0")
37//!     .build()?;
38//!
39//! // reqwest-like API: response has body-reading methods
40//! // Compressed responses are automatically decompressed
41//! let data: MyData = client
42//!     .get("https://example.com/api")
43//!     .send()
44//!     .await?
45//!     .json()
46//!     .await?;
47//! ```
48
49/// Builder for configuring and constructing the HTTP client.
50mod builder;
51/// The HTTP client implementation.
52mod client;
53/// Client configuration types.
54mod config;
55mod connector;
56/// Error types returned by the HTTP client.
57mod error;
58mod layers;
59pub mod otel;
60/// Request builder types.
61mod request;
62/// Response types with body-size-limited readers.
63mod response;
64pub mod security;
65mod tls;
66
67pub use builder::HttpClientBuilder;
68pub use client::HttpClient;
69/// TLS building blocks shared with other transport crates (e.g. the upstream
70/// proxy engine) so every outbound `ClientConfig` goes through the same
71/// provider selection and FIPS hardening.
72pub use config::{ClientAuthConfig, TlsConfig, TlsVersion};
73pub use config::{
74    DEFAULT_USER_AGENT, ExplicitProxy, ExponentialBackoff, HttpClientConfig,
75    IDEMPOTENCY_KEY_HEADER, OutboundProxy, RateLimitConfig, RedirectConfig, RetryConfig,
76    RetryTrigger, TlsRootConfig, TransportSecurity, is_idempotent_method,
77};
78pub use error::{HttpError, InvalidUriKind, ProxyErrorKind};
79#[cfg(feature = "otel")]
80pub use layers::{ClassifyFn, MetricsLayer, MetricsService, default_classify};
81pub use layers::{
82    OtelLayer, OtelService, RETRY_ATTEMPT_HEADER, RetryLayer, RetryService, SecureRedirectPolicy,
83    UserAgentLayer, UserAgentService,
84};
85pub use request::{RequestBuilder, RequestType};
86pub use response::{HttpResponse, LimitedBody, ResponseBody};
87pub use security::{attach_bearer_http, attach_internal_token_http};
88pub use tls::TlsConfigError;
89pub use tls::{custom_roots_client_config, native_roots_client_config, webpki_roots_client_config};