Skip to main content

cuenv_core/
http.rs

1//! HTTP helpers shared across the cuenv workspace.
2
3use std::sync::OnceLock;
4
5static RUSTLS_PROVIDER_INSTALLED: OnceLock<()> = OnceLock::new();
6
7/// Install the process-wide rustls crypto provider required by reqwest.
8///
9/// The workspace uses reqwest with the `rustls-no-provider` feature, so the
10/// application must install a provider before constructing clients. We do that
11/// once per process and accept any already-installed provider.
12pub fn ensure_rustls_crypto_provider() {
13    RUSTLS_PROVIDER_INSTALLED.get_or_init(|| {
14        if rustls::crypto::CryptoProvider::get_default().is_none() {
15            if rustls::crypto::ring::default_provider()
16                .install_default()
17                .is_err()
18            {
19                panic!(
20                    "Failed to install rustls crypto provider. \
21                     cuenv requires a working rustls provider when built with `rustls-no-provider`."
22                );
23            }
24            if rustls::crypto::CryptoProvider::get_default().is_none() {
25                panic!(
26                    "rustls crypto provider is still missing after installation attempt. \
27                     Another incompatible provider may have been installed earlier in the process."
28                );
29            }
30        }
31    });
32}