Skip to main content

max / makenotwork

952 B · 23 lines History Blame Raw
1 //! The rustls crypto provider for outbound HTTP.
2 //!
3 //! reqwest is compiled `rustls-no-provider` to keep aws-lc-rs (a C backend) out
4 //! of the tree, which means a client cannot be built until a provider has been
5 //! installed process-wide. Every outbound client therefore comes from
6 //! [`builder`], so the two cannot get out of order.
7
8 /// Install ring as the process-wide rustls crypto provider. Idempotent (guarded
9 /// by a `Once`), and a no-op if the process already installed one.
10 pub fn install_crypto_provider() {
11 static INSTALLED: std::sync::Once = std::sync::Once::new();
12 INSTALLED.call_once(|| {
13 let _ = rustls::crypto::ring::default_provider().install_default();
14 });
15 }
16
17 /// A `reqwest` client builder with a provider guaranteed to be installed.
18 /// Callers add their own timeouts and policy, then `.build()`.
19 pub fn builder() -> reqwest::ClientBuilder {
20 install_crypto_provider();
21 reqwest::Client::builder()
22 }
23