Skip to content

Commit

Permalink
fix(hyper-rustls): reverted the hyper client to enforce https and add…
Browse files Browse the repository at this point in the history
…ed an insecure client builder
  • Loading branch information
Pierre Seguin committed May 28, 2022
1 parent 0944870 commit a65033c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ pub trait HyperClientBuilder {
/// Create a hyper::Client
fn build_hyper_client(self) -> hyper::Client<Self::Connector>;

/// Create a `hyper::Client` (HTTPS not required)
fn build_insecure_http_hyper_client(self) -> hyper::Client<Self::Connector>;

/// Create a `hyper::Client` for tests (HTTPS not required)
#[doc(hidden)]
fn build_test_hyper_client(self) -> hyper::Client<Self::Connector>;
Expand Down Expand Up @@ -777,6 +780,22 @@ impl HyperClientBuilder for DefaultHyperClient {
type Connector = hyper_tls::HttpsConnector<hyper::client::connect::HttpConnector>;

fn build_hyper_client(self) -> hyper::Client<Self::Connector> {
#[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<Self::Connector> {
#[cfg(feature = "hyper-rustls")]
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
Expand Down Expand Up @@ -819,6 +838,10 @@ where
self
}

fn build_insecure_http_hyper_client(self) -> hyper::Client<C> {
self
}

fn build_test_hyper_client(self) -> hyper::Client<Self::Connector> {
self
}
Expand Down

0 comments on commit a65033c

Please sign in to comment.