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.
25pub fn with_webpki_root_fallback(builder: reqwest::ClientBuilder) -> reqwest::ClientBuilder {
26    #[cfg(any(all(unix, not(target_os = "android")), target_os = "windows"))]
27    {
28        let certs = webpki_root_certs::TLS_SERVER_ROOT_CERTS
29            .iter()
30            .map(|cert| {
31                reqwest::Certificate::from_der(cert.as_ref())
32                    // webpki-root-certs is generated as valid DER; failure means the dependency is corrupt.
33                    .expect("webpki root certificate must be valid DER")
34            })
35            .collect::<Vec<_>>();
36        builder.tls_certs_merge(certs)
37    }
38
39    #[cfg(not(any(all(unix, not(target_os = "android")), target_os = "windows")))]
40    {
41        builder
42    }
43}