holger-traits 3.3.2

holger's shared vocabulary: ArtifactId, RepositoryBackendTrait, ZnippyPlugin discriminants, and ArtifactFormat — including `ArtifactFormat::home()`, the format→crate map that answers which crate serves PyPI when grepping cannot.
Documentation
//! **The one HTTP client setup** every reqwest client of Holger shares (feature `http`;
//! `http-blocking` adds the blocking builder): reqwest 0.13 with reqwest 0.12 `rustls-tls`
//! behaviour — the ring provider and the bundled Mozilla roots (webpki), not 0.13's
//! aws-lc-rs + OS trust store. Roots added later on the builder are merged in, as in 0.12.

fn roots() -> impl Iterator<Item = reqwest::Certificate> {
    let _ = rustls::crypto::ring::default_provider().install_default();
    webpki_root_certs::TLS_SERVER_ROOT_CERTS
        .iter()
        .filter_map(|c| reqwest::Certificate::from_der(c).ok())
}

/// The async builder with the ring provider and the webpki roots.
pub fn tls_roots(b: reqwest::ClientBuilder) -> reqwest::ClientBuilder {
    b.tls_certs_only(roots())
}

/// The blocking builder with the ring provider and the webpki roots.
#[cfg(feature = "http-blocking")]
pub fn tls_roots_blocking(b: reqwest::blocking::ClientBuilder) -> reqwest::blocking::ClientBuilder {
    b.tls_certs_only(roots())
}

/// Read a response body into memory, refusing one larger than `max`: `Content-Length` is
/// checked up front and the cap is enforced again while streaming, so a lying or absent
/// length cannot bypass it.
pub async fn read_capped(mut resp: reqwest::Response, max: u64) -> anyhow::Result<Vec<u8>> {
    if let Some(len) = resp.content_length() {
        if len > max {
            anyhow::bail!("response body {len} bytes exceeds cap of {max} bytes");
        }
    }
    let mut buf: Vec<u8> = Vec::new();
    while let Some(chunk) = resp.chunk().await? {
        if buf.len() as u64 + chunk.len() as u64 > max {
            anyhow::bail!("response body exceeded cap of {max} bytes");
        }
        buf.extend_from_slice(&chunk);
    }
    Ok(buf)
}