1#![cfg_attr(
2 not(any(feature = "https", feature = "nativetls", feature = "__rustls")),
3 doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`]."
4)]
5#![cfg_attr(
6 all(
7 any(feature = "https", feature = "nativetls"),
8 not(feature = "__rustls")
9 ),
10 doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`] or [`hyper_tls`]."
11)]
12#![cfg_attr(
13 all(
14 feature = "__rustls",
15 not(any(feature = "https", feature = "nativetls"))
16 ),
17 doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`] or [`hyper_rustls`]."
18)]
19#![cfg_attr(
20 all(any(feature = "https", feature = "nativetls"), feature = "__rustls"),
21 doc = "Includes helper functions to build [`Client`]s, and some re-exports from [`hyper_util::client::legacy`], [`hyper_tls`], or [`hyper_rustls`]."
22)]
23use hyper::body::Body as HttpBody;
25#[cfg(feature = "__rustls")]
26#[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
27pub use hyper_rustls::HttpsConnector as RustlsConnector;
28#[cfg(feature = "https")]
29#[cfg_attr(docsrs, doc(cfg(feature = "https")))]
30pub use hyper_tls::HttpsConnector;
31#[cfg(feature = "nativetls")]
32#[cfg_attr(docsrs, doc(cfg(feature = "nativetls")))]
33pub use hyper_tls::HttpsConnector as NativeTlsConnector;
34use hyper_util::client::legacy::connect::Connect;
35pub use hyper_util::client::legacy::connect::HttpConnector;
36pub use hyper_util::client::legacy::{Builder, Client};
37
38#[must_use]
40pub fn builder() -> Builder {
41 Builder::new(hyper_util::rt::TokioExecutor::new())
42}
43
44#[must_use]
46pub fn http_default<B>() -> Client<HttpConnector, B>
47where
48 B: HttpBody + Send,
49 B::Data: Send,
50{
51 Builder::new(hyper_util::rt::TokioExecutor::new()).build_http()
52}
53
54#[cfg(any(feature = "https", feature = "nativetls"))]
56#[cfg_attr(docsrs, doc(cfg(any(feature = "https", feature = "nativetls"))))]
57#[inline]
58#[must_use]
59pub fn https_default<B>() -> Client<NativeTlsConnector<HttpConnector>, B>
60where
61 B: HttpBody + Send,
62 B::Data: Send,
63{
64 nativetls_default()
65}
66
67#[cfg(feature = "nativetls")]
69#[cfg_attr(docsrs, doc(cfg(feature = "nativetls")))]
70#[must_use]
71pub fn nativetls_default<B>() -> Client<NativeTlsConnector<HttpConnector>, B>
72where
73 B: HttpBody + Send,
74 B::Data: Send,
75{
76 Builder::new(hyper_util::rt::TokioExecutor::new()).build(NativeTlsConnector::new())
77}
78
79#[cfg(feature = "__rustls")]
107#[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
108#[must_use]
109pub fn rustls_default<B>() -> Client<RustlsConnector<HttpConnector>, B>
110where
111 B: HttpBody + Send,
112 B::Data: Send,
113{
114 let conn = hyper_rustls::HttpsConnectorBuilder::new();
115 #[cfg(all(
116 any(feature = "rustls-ring", feature = "rustls-aws-lc"),
117 feature = "rustls-webpki-roots"
118 ))]
119 let conn = conn.with_webpki_roots();
120 #[cfg(all(
121 any(feature = "rustls-ring", feature = "rustls-aws-lc"),
122 all(not(feature = "rustls-webpki-roots"), feature = "rustls-native-roots")
123 ))]
124 let conn = conn
125 .with_native_roots()
126 .expect("no native root CA certificates found");
127 #[cfg(all(
128 any(feature = "rustls-ring", feature = "rustls-aws-lc"),
129 any(feature = "rustls-webpki-roots", feature = "rustls-native-roots")
130 ))]
131 let conn = conn.https_only();
132 #[cfg(feature = "http1")]
133 let conn = conn.enable_http1();
134 #[cfg(feature = "rustls-http2")]
135 let conn = conn.enable_http2();
136 Builder::new(hyper_util::rt::TokioExecutor::new()).build(conn.build())
137}
138
139pub fn with_connector_default<C, B>(conn: C) -> Client<C, B>
141where
142 C: Connect + Clone,
143 B: HttpBody + Send,
144 B::Data: Send,
145{
146 Builder::new(hyper_util::rt::TokioExecutor::new()).build(conn)
147}