Skip to main content

aube_util/http/
mod.rs

1//! HTTP client helpers reused across aube crates.
2//!
3//! The npm registry path is dominated by cold TCP+TLS handshakes,
4//! per-origin DNS lookups, and per-request priority noise. Each helper
5//! here addresses one of those costs without owning a `reqwest::Client`
6//! itself — call sites keep their builders and pass them in.
7//!
8//! Killswitch convention follows aube-util: every optimization that
9//! defaults ON ships an `AUBE_DISABLE_*` env var. Each killswitch is
10//! named in the doc comment of the function reading it so cargo doc
11//! enumerates them.
12
13pub mod prewarm;
14pub mod priority;
15pub mod race;
16pub mod resolve;
17pub mod ticket_cache;
18
19/// Add Mozilla's baked-in root bundle as extra trust roots while keeping
20/// reqwest's rustls-platform-verifier OS trust store active.
21///
22/// reqwest 0.13 can merge extra roots with the platform verifier on Unix
23/// (except Android) and Windows. On other targets, leave the builder alone
24/// so client construction does not fail at runtime.
25///
26/// Compiled to a no-op when the `rustls` feature is not enabled — reqwest's
27/// `Certificate`/`tls_certs_merge` APIs only exist with a TLS backend, and
28/// this crate leaves that choice to the final binary (the aube binary selects
29/// rustls via aube-registry's defaults).
30pub fn with_webpki_root_fallback(builder: reqwest::ClientBuilder) -> reqwest::ClientBuilder {
31    #[cfg(all(
32        feature = "rustls",
33        any(all(unix, not(target_os = "android")), target_os = "windows")
34    ))]
35    {
36        let certs = webpki_root_certs::TLS_SERVER_ROOT_CERTS
37            .iter()
38            .map(|cert| {
39                reqwest::Certificate::from_der(cert.as_ref())
40                    // webpki-root-certs is generated as valid DER; failure means the dependency is corrupt.
41                    .expect("webpki root certificate must be valid DER")
42            })
43            .collect::<Vec<_>>();
44        builder.tls_certs_merge(certs)
45    }
46
47    #[cfg(not(all(
48        feature = "rustls",
49        any(all(unix, not(target_os = "android")), target_os = "windows")
50    )))]
51    {
52        builder
53    }
54}