http-request 23.3.0

http-request is a lightweight, efficient library for building, sending, and handling HTTP/HTTPS requests in Rust applications. It provides a simple and intuitive API, allowing developers to easily interact with web services, whether they use the "HTTP" or "HTTPS" protocol. The library supports various HTTP methods, custom headers, request bodies, timeout, automatic handling of redirects (including detecting redirect loops), and enhanced response body decoding (both automatic and manual), enabling fast and secure communication. Whether working with secure "HTTPS" connections or standard "HTTP" requests, the library is optimized for performance, minimal resource usage, and easy integration into Rust projects.
Documentation
use super::*;

/// Cache key identifying a reusable upstream transport channel.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub(crate) struct PoolKey {
    /// Whether the target connection uses TLS.
    pub(crate) is_https: bool,
    /// Lowercased target host or IP literal.
    pub(crate) host: String,
    /// Target TCP port.
    pub(crate) port: u16,
    /// Optional proxy identity (`None` for direct connections).
    pub(crate) proxy: Option<ProxyKey>,
    /// Deterministic fingerprint of configured TLS root certificates (`0` for default WebPKI roots).
    pub(crate) root_cert_fingerprint: u64,
    /// Configured synchronous socket timeout in milliseconds (`0` for asynchronous pools).
    pub(crate) sync_timeout_ms: u64,
}

/// Hashable proxy identity component for [`PoolKey`].
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub(crate) struct ProxyKey {
    /// Proxy protocol family tag (`0 = Http`, `1 = Https`, `2 = Socks5`).
    pub(crate) proxy_type_tag: u8,
    /// Proxy hostname or IP.
    pub(crate) host: String,
    /// Proxy port.
    pub(crate) port: u16,
    /// Optional username.
    pub(crate) username: Option<String>,
    /// Optional password.
    pub(crate) password: Option<String>,
}

/// Borrowed pool lookup parameters avoiding heap allocation and wide argument lists.
#[derive(Clone, Copy)]
pub(crate) struct PoolLookup<'a> {
    /// Whether the target connection uses TLS.
    pub(crate) is_https: bool,
    /// Target host or IP literal.
    pub(crate) host: &'a str,
    /// Effective target TCP port.
    pub(crate) port: u16,
    /// Optional proxy identity.
    pub(crate) proxy: Option<&'a Proxy>,
    /// Optional custom TLS trust store.
    pub(crate) roots: Option<&'a RootCertStore>,
    /// Precomputed TLS trust store fingerprint.
    pub(crate) root_fp: u64,
    /// Synchronous socket timeout in milliseconds (`0` for async pools).
    pub(crate) sync_timeout_ms: u64,
}

/// One idle HTTP/1.1 connection paired with the timestamp when it entered the pool.
pub(crate) struct PooledConn<T> {
    /// The keep-alive transport.
    pub(crate) stream: T,
    /// Timestamp when this connection became idle.
    pub(crate) idle_since: Instant,
}

/// One lock stripe inside [`StripedH1Pool`] storing idle connections with O(1) entry counting.
pub(crate) struct H1PoolStripe<T> {
    /// Origin buckets held inside this stripe.
    pub(crate) entries: Vec<H1StripeEntry<T>>,
    /// Exact count of idle connections currently stored across all buckets in this stripe.
    pub(crate) total: usize,
}

/// Bitmask-indexed multi-stripe HTTP/1.1 connection pool minimizing cross-thread mutex contention.
pub(crate) struct StripedH1Pool<T> {
    /// Independent per-stripe mutexes.
    pub(crate) stripes: [Mutex<H1PoolStripe<T>>; H1_POOL_STRIPES],
    /// Bit `i` is set while stripe `i` contains at least one idle connection.
    pub(crate) non_empty_mask: AtomicU64,
}