#![cfg_attr(
not(any(feature = "https", feature = "nativetls", feature = "__rustls")),
doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`]."
)]
#![cfg_attr(
all(
any(feature = "https", feature = "nativetls"),
not(feature = "__rustls")
),
doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`] or [`hyper_tls`]."
)]
#![cfg_attr(
all(
feature = "__rustls",
not(any(feature = "https", feature = "nativetls"))
),
doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`] or [`hyper_rustls`]."
)]
#![cfg_attr(
all(any(feature = "https", feature = "nativetls"), feature = "__rustls"),
doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`], [`hyper_tls`], or [`hyper_rustls`]."
)]
use hyper::body::Body as HttpBody;
#[cfg(feature = "__rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
pub use hyper_rustls::HttpsConnector as RustlsConnector;
#[cfg(feature = "https")]
#[cfg_attr(docsrs, doc(cfg(feature = "https")))]
pub use hyper_tls::HttpsConnector;
#[cfg(feature = "nativetls")]
#[cfg_attr(docsrs, doc(cfg(feature = "nativetls")))]
pub use hyper_tls::HttpsConnector as NativeTlsConnector;
use hyper_util::client::legacy::connect::Connect;
pub use hyper_util::client::legacy::connect::HttpConnector;
pub use hyper_util::client::legacy::{Builder, Client};
#[must_use]
pub fn builder() -> Builder {
Builder::new(hyper_util::rt::TokioExecutor::new())
}
#[must_use]
pub fn http_default<B>() -> Client<HttpConnector, B>
where
B: HttpBody + Send,
B::Data: Send,
{
Builder::new(hyper_util::rt::TokioExecutor::new()).build_http()
}
#[cfg(any(feature = "https", feature = "nativetls"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "https", feature = "nativetls"))))]
#[inline]
#[must_use]
pub fn https_default<B>() -> Client<NativeTlsConnector<HttpConnector>, B>
where
B: HttpBody + Send,
B::Data: Send,
{
nativetls_default()
}
#[cfg(feature = "nativetls")]
#[cfg_attr(docsrs, doc(cfg(feature = "nativetls")))]
#[must_use]
pub fn nativetls_default<B>() -> Client<NativeTlsConnector<HttpConnector>, B>
where
B: HttpBody + Send,
B::Data: Send,
{
Builder::new(hyper_util::rt::TokioExecutor::new()).build(NativeTlsConnector::new())
}
#[cfg(feature = "__rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
#[must_use]
pub fn rustls_default<B>() -> Client<RustlsConnector<HttpConnector>, B>
where
B: HttpBody + Send,
B::Data: Send,
{
let conn = hyper_rustls::HttpsConnectorBuilder::new();
#[cfg(all(
any(feature = "rustls-ring", feature = "rustls-aws-lc"),
feature = "rustls-webpki-roots"
))]
let conn = conn.with_webpki_roots();
#[cfg(all(
any(feature = "rustls-ring", feature = "rustls-aws-lc"),
all(not(feature = "rustls-webpki-roots"), feature = "rustls-native-roots")
))]
let conn = conn
.with_native_roots()
.expect("no native root CA certificates found");
#[cfg(all(
any(feature = "rustls-ring", feature = "rustls-aws-lc"),
any(feature = "rustls-webpki-roots", feature = "rustls-native-roots")
))]
let conn = conn.https_only();
#[cfg(feature = "http1")]
let conn = conn.enable_http1();
#[cfg(feature = "rustls-http2")]
let conn = conn.enable_http2();
Builder::new(hyper_util::rt::TokioExecutor::new()).build(conn.build())
}
pub fn with_connector_default<C, B>(conn: C) -> Client<C, B>
where
C: Connect + Clone,
B: HttpBody + Send,
B::Data: Send,
{
Builder::new(hyper_util::rt::TokioExecutor::new()).build(conn)
}