use hyper::client::HttpConnector;
use hyper::Client;
#[cfg(feature = "rust-tls")]
pub(crate) use hyper_rustls as tls;
#[cfg(not(feature = "rust-tls"))]
pub(crate) use hyper_tls as tls;
#[cfg(feature = "rust-tls")]
use rustls::ClientConfig;
#[cfg(feature = "rust-tls")]
use tls::ConfigBuilderExt;
#[cfg(all(feature = "rust-tls", feature = "http2"))]
pub(crate) fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
where
T: hyper::body::HttpBody + std::marker::Send,
<T as hyper::body::HttpBody>::Data: Send,
{
let https_connector = tls::HttpsConnectorBuilder::new()
.with_tls_config(
ClientConfig::builder()
.with_safe_defaults()
.with_native_roots()
.with_no_client_auth(),
)
.https_only()
.enable_http2()
.build();
let mut builder = Client::builder();
builder.http2_only(true);
builder.build::<_, T>(https_connector)
}
#[cfg(all(feature = "rust-tls", not(feature = "http2")))]
pub(crate) fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
where
T: hyper::body::HttpBody + std::marker::Send,
<T as hyper::body::HttpBody>::Data: Send,
{
let https_connector = tls::HttpsConnectorBuilder::new()
.with_tls_config(
ClientConfig::builder()
.with_safe_defaults()
.with_native_roots()
.with_no_client_auth(),
)
.https_only()
.enable_http2()
.build();
Client::builder().build::<_, T>(https_connector)
}
#[cfg(not(feature = "rust-tls"))]
pub(crate) fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
where
T: hyper::body::HttpBody + std::marker::Send,
<T as hyper::body::HttpBody>::Data: Send,
{
let https_connector = tls::HttpsConnector::new();
Client::builder().build::<_, T>(https_connector)
}