1use std::sync::Once;
4
5use rustls::{ClientConfig, RootCertStore};
6
7static RUSTLS_PROVIDER_INIT: Once = Once::new();
8
9pub fn install_default_rustls_crypto_provider() {
15 RUSTLS_PROVIDER_INIT.call_once(|| {
16 if rustls::crypto::ring::default_provider()
17 .install_default()
18 .is_err()
19 {
20 tracing::debug!(
21 "rustls crypto provider already installed; keeping existing process-level provider"
22 );
23 }
24 });
25}
26
27pub fn webpki_builder() -> reqwest::ClientBuilder {
30 reqwest::Client::builder().tls_backend_preconfigured(webpki_client_config())
31}
32
33fn webpki_client_config() -> ClientConfig {
34 install_default_rustls_crypto_provider();
35 let roots = RootCertStore {
36 roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
37 };
38 let mut config = ClientConfig::builder()
39 .with_root_certificates(roots)
40 .with_no_client_auth();
41 config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
44 config
45}
46
47#[cfg(test)]
48#[path = "http_client/tests.rs"]
49mod tests;