1use hyper::client::HttpConnector;
17use hyper::Client;
18
19#[cfg(feature = "rust-tls")]
20pub use hyper_rustls as tls;
21#[cfg(not(feature = "rust-tls"))]
22pub use hyper_tls as tls;
23#[cfg(feature = "rust-tls")]
24use rustls::ClientConfig;
25#[cfg(feature = "rust-tls")]
26use tls::ConfigBuilderExt;
27
28#[cfg(all(feature = "rust-tls", feature = "http2"))]
29pub fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
30where
31 T: hyper::body::HttpBody + std::marker::Send,
32 <T as hyper::body::HttpBody>::Data: Send,
33{
34 let https_connector = tls::HttpsConnectorBuilder::new()
36 .with_tls_config(
38 ClientConfig::builder()
39 .with_safe_defaults()
40 .with_native_roots()
41 .with_no_client_auth(),
42 )
43 .https_only()
44 .enable_http2()
45 .build();
46
47 let mut builder = Client::builder();
48 builder.http2_only(true);
49
50 builder.build::<_, T>(https_connector)
51}
52
53#[cfg(all(feature = "rust-tls", not(feature = "http2")))]
54pub fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
55where
56 T: hyper::body::HttpBody + std::marker::Send,
57 <T as hyper::body::HttpBody>::Data: Send,
58{
59 let https_connector = tls::HttpsConnectorBuilder::new()
61 .with_tls_config(
63 ClientConfig::builder()
64 .with_safe_defaults()
65 .with_native_roots()
66 .with_no_client_auth(),
67 )
68 .https_only()
69 .enable_http2()
70 .build();
71
72 Client::builder().build::<_, T>(https_connector)
73}
74
75#[cfg(not(feature = "rust-tls"))]
76pub fn get_https_client<T>() -> Client<tls::HttpsConnector<HttpConnector>, T>
77where
78 T: hyper::body::HttpBody + std::marker::Send,
79 <T as hyper::body::HttpBody>::Data: Send,
80{
81 let https_connector = tls::HttpsConnector::new();
83 Client::builder().build::<_, T>(https_connector)
84}