| 1 | //! Process-wide TLS bootstrap plus the platform HTTP client constructors that |
| 2 | //! depend on it. Every reqwest client Codewhale builds goes through here so |
| 3 | //! the rustls crypto provider is installed exactly once, before the first |
| 4 | //! client, on every path (TUI, CLI, tests). |
| 5 | |
| 6 | /// Install the rustls `ring` crypto provider if no provider is installed yet. |
| 7 | /// Idempotent; a second call is a no-op. |
| 8 | pub fn ensure_rustls_crypto_provider() { |
| 9 | let _ = rustls::crypto::ring::default_provider().install_default(); |
| 10 | } |
| 11 | |
| 12 | /// A ready platform HTTP client (provider installed, platform verifier). |
| 13 | pub fn reqwest_client() -> reqwest::Client { |
| 14 | ensure_rustls_crypto_provider(); |
| 15 | reqwest_client_builder() |
| 16 | .build() |
| 17 | .expect("build platform HTTP client") |
| 18 | } |
| 19 | |
| 20 | /// The platform HTTP client builder, with the crypto provider installed. |
| 21 | pub fn reqwest_client_builder() -> reqwest::ClientBuilder { |
| 22 | ensure_rustls_crypto_provider(); |
| 23 | crate::platform_http_client_builder() |
| 24 | } |
| 25 | |
| 26 | /// The blocking platform HTTP client builder, with the crypto provider installed. |
| 27 | pub fn reqwest_blocking_client_builder() -> reqwest::blocking::ClientBuilder { |
| 28 | ensure_rustls_crypto_provider(); |
| 29 | crate::platform_blocking_http_client_builder() |
| 30 | } |
| 31 |