Allow testing without https

This commit is contained in:
Dirkjan Ochtman
2022-04-11 11:38:25 +02:00
parent f9c59bb743
commit 32b6d8fa63
2 changed files with 25 additions and 1 deletions

View File

@@ -727,6 +727,10 @@ pub trait HyperClientBuilder {
/// Create a hyper::Client
fn build_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>;
}
#[cfg(feature = "hyper-rustls")]
@@ -781,6 +785,22 @@ impl HyperClientBuilder for DefaultHyperClient {
.pool_max_idle_per_host(0)
.build::<_, hyper::Body>(connector)
}
fn build_test_hyper_client(self) -> hyper::Client<Self::Connector> {
#[cfg(feature = "hyper-rustls")]
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.https_or_http()
.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)
}
}
impl<C> HyperClientBuilder for hyper::Client<C>
@@ -792,6 +812,10 @@ where
fn build_hyper_client(self) -> hyper::Client<C> {
self
}
fn build_test_hyper_client(self) -> hyper::Client<Self::Connector> {
self
}
}
/// How should the acquired tokens be stored?

View File

@@ -216,7 +216,7 @@ async fn create_installed_flow_auth(
}
let mut builder = InstalledFlowAuthenticator::builder(app_secret, method)
.flow_delegate(Box::new(FD(DefaultHyperClient.build_hyper_client())));
.flow_delegate(Box::new(FD(DefaultHyperClient.build_test_hyper_client())));
builder = if let Some(filename) = filename {
builder.persist_tokens_to_disk(filename)