From b4048209147f776b04bdb41b1073de45dd82fb33 Mon Sep 17 00:00:00 2001 From: Pierre Seguin Date: Sat, 28 May 2022 11:32:01 -0400 Subject: [PATCH] fix(hyper-rustls): reverted the hyper client to enforce https and added an insecure client builder --- src/authenticator.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/authenticator.rs b/src/authenticator.rs index d862aa28..0df1a2b4 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -746,6 +746,9 @@ pub trait HyperClientBuilder { /// Create a hyper::Client fn build_hyper_client(self) -> hyper::Client; + /// Create a `hyper::Client` (HTTPS not required) + fn build_insecure_http_hyper_client(self) -> hyper::Client; + /// Create a `hyper::Client` for tests (HTTPS not required) #[doc(hidden)] fn build_test_hyper_client(self) -> hyper::Client; @@ -789,6 +792,22 @@ impl HyperClientBuilder for DefaultHyperClient { type Connector = hyper_tls::HttpsConnector; fn build_hyper_client(self) -> hyper::Client { + #[cfg(feature = "hyper-rustls")] + let connector = hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .https_only() + .enable_http1() + .enable_http2() + .build(); + #[cfg(all(not(feature = "hyper-rustls"), feature = "hyper-tls"))] + let connector = hyper_tls::HttpsConnector::new(); + + hyper::Client::builder() + .pool_max_idle_per_host(0) + .build::<_, hyper::Body>(connector) + } + + fn build_insecure_http_hyper_client(self) -> hyper::Client { #[cfg(feature = "hyper-rustls")] let connector = hyper_rustls::HttpsConnectorBuilder::new() .with_native_roots() @@ -834,6 +853,10 @@ where self } + fn build_insecure_http_hyper_client(self) -> hyper::Client { + self + } + fn build_test_hyper_client(self) -> hyper::Client { self }