mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-23 10:28:54 +01:00
Allow testing without https
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user