twilight_http/client/
connector.rs1#[cfg(any(
5 feature = "rustls-native-roots",
6 feature = "rustls-platform-verifier",
7 feature = "rustls-webpki-roots"
8))]
9type HttpsConnector<T> = hyper_rustls::HttpsConnector<T>;
10#[cfg(all(
12 feature = "native-tls",
13 not(any(
14 feature = "rustls-native-roots",
15 feature = "rustls-platform-verifier",
16 feature = "rustls-webpki-roots"
17 ))
18))]
19type HttpsConnector<T> = hyper_tls::HttpsConnector<T>;
20
21#[cfg(feature = "hickory")]
23type HttpConnector = hyper_hickory::TokioHickoryHttpConnector;
24#[cfg(not(feature = "hickory"))]
26type HttpConnector = hyper_util::client::legacy::connect::HttpConnector;
27
28#[cfg(any(
30 feature = "native-tls",
31 feature = "rustls-native-roots",
32 feature = "rustls-platform-verifier",
33 feature = "rustls-webpki-roots",
34))]
35pub type Connector = HttpsConnector<HttpConnector>;
36#[cfg(not(any(
38 feature = "native-tls",
39 feature = "rustls-native-roots",
40 feature = "rustls-platform-verifier",
41 feature = "rustls-webpki-roots"
42)))]
43pub type Connector = HttpConnector;
44
45pub fn create() -> Connector {
47 #[cfg(not(feature = "hickory"))]
48 let mut connector = HttpConnector::new();
49 #[cfg(feature = "hickory")]
50 let mut connector = hyper_hickory::TokioHickoryResolver::default().into_http_connector();
51
52 connector.enforce_http(false);
53
54 #[cfg(any(
55 feature = "rustls-native-roots",
56 feature = "rustls-platform-verifier",
57 feature = "rustls-webpki-roots"
58 ))]
59 let connector = {
60 #[cfg(not(any(feature = "rustls-ring", feature = "rustls-aws_lc_rs")))]
61 let crypto_provider = rustls::crypto::CryptoProvider::get_default()
62 .expect("No default crypto provider installed or configured via crate features")
63 .clone();
64 #[cfg(feature = "rustls-aws_lc_rs")]
65 let crypto_provider = rustls::crypto::aws_lc_rs::default_provider();
66 #[cfg(all(feature = "rustls-ring", not(feature = "rustls-aws_lc_rs")))]
67 let crypto_provider = rustls::crypto::ring::default_provider();
68
69 #[cfg(all(
70 feature = "rustls-native-roots",
71 not(feature = "rustls-platform-verifier")
72 ))]
73 let connector = hyper_rustls::HttpsConnectorBuilder::new()
74 .with_provider_and_native_roots(crypto_provider)
75 .expect("no native roots found")
76 .https_or_http()
77 .enable_http1()
78 .enable_http2()
79 .wrap_connector(connector);
80 #[cfg(feature = "rustls-platform-verifier")]
81 let connector = hyper_rustls::HttpsConnectorBuilder::new()
82 .with_provider_and_platform_verifier(crypto_provider)
83 .expect("no usable cipher suites in crypto provider")
84 .https_or_http()
85 .enable_http1()
86 .enable_http2()
87 .wrap_connector(connector);
88 #[cfg(all(
89 feature = "rustls-webpki-roots",
90 not(any(feature = "rustls-native-roots", feature = "rustls-platform-verifier"))
91 ))]
92 let connector = hyper_rustls::HttpsConnectorBuilder::new()
93 .with_provider_and_webpki_roots(crypto_provider)
94 .expect("no usable cipher suites in crypto provider")
95 .https_or_http()
96 .enable_http1()
97 .enable_http2()
98 .wrap_connector(connector);
99
100 connector
101 };
102
103 #[cfg(all(
104 feature = "native-tls",
105 not(feature = "rustls-native-roots"),
106 not(feature = "rustls-platform-verifier"),
107 not(feature = "rustls-webpki-roots")
108 ))]
109 let connector = hyper_tls::HttpsConnector::new_with_connector(connector);
110
111 connector
112}