async_http_client_lite/
client_tls.rs

1#[cfg(feature = "tls")]
2pub(crate) use async_stream_tls_upgrader::UnionableTlsClientUpgrader;
3
4#[cfg(feature = "tls__async_tls")]
5pub use async_stream_tls_upgrader::async_tls_client::{
6    ClientConfig as AsyncTlsRustlsClientConfig, TlsConnector as AsyncTlsTlsConnector,
7    TLS_SERVER_ROOTS as ASYNC_TLS_WEBPKI_ROOTS_TLS_SERVER_ROOTS,
8};
9#[cfg(feature = "tls__async_tls")]
10use async_stream_tls_upgrader::AsyncTlsClientTlsUpgrader;
11
12#[cfg(feature = "tls__async_native_tls")]
13pub use async_stream_tls_upgrader::async_native_tls_client::{
14    Certificate as AsyncNativeTlsCertificate, Identity as AsyncNativeTlsIdentity,
15    Protocol as AsyncNativeTlsProtocol, TlsConnector as AsyncNativeTlsTlsConnector,
16};
17#[cfg(feature = "tls__async_native_tls")]
18use async_stream_tls_upgrader::AsyncNativeTlsClientTlsUpgrader;
19
20//
21//
22//
23pub struct ClientTls {
24    #[allow(dead_code)]
25    kind: ClientTlsKind,
26    #[allow(dead_code)]
27    domain: String,
28}
29impl ClientTls {
30    pub fn new(kind: ClientTlsKind, domain: String) -> Self {
31        Self { kind, domain }
32    }
33
34    #[cfg(feature = "tls")]
35    pub(crate) fn into_tls_upgrader(self) -> UnionableTlsClientUpgrader {
36        match self.kind {
37            #[cfg(feature = "tls__async_tls")]
38            ClientTlsKind::AsyncTls(tls_connector) => UnionableTlsClientUpgrader::AsyncTls(
39                AsyncTlsClientTlsUpgrader::new(tls_connector, self.domain.to_owned()),
40            ),
41            #[cfg(feature = "tls__async_native_tls")]
42            ClientTlsKind::AsyncNativeTls(tls_connector) => {
43                UnionableTlsClientUpgrader::AsyncNativeTls(AsyncNativeTlsClientTlsUpgrader::new(
44                    tls_connector,
45                    self.domain,
46                ))
47            }
48        }
49    }
50}
51
52//
53//
54//
55pub enum ClientTlsKind {
56    #[cfg(feature = "tls__async_tls")]
57    AsyncTls(AsyncTlsTlsConnector),
58    #[cfg(feature = "tls__async_native_tls")]
59    AsyncNativeTls(AsyncNativeTlsTlsConnector),
60}
61impl ClientTlsKind {
62    #[cfg(feature = "tls__async_tls")]
63    pub fn default_async_tls() -> Self {
64        Self::AsyncTls(Default::default())
65    }
66    #[cfg(feature = "tls__async_native_tls")]
67    pub fn default_async_native_tls() -> Self {
68        Self::AsyncNativeTls(Default::default())
69    }
70}