1use std::fmt::Debug;
4use std::time::Duration;
5
6#[non_exhaustive]
8#[derive(Clone)]
9pub struct Config {
10 pub http_keep_alive: bool,
16 pub tcp_no_delay: bool,
22 pub timeout: Option<Duration>,
26 pub max_connections_per_host: usize,
37 #[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
39 #[cfg(all(feature = "h1_client", feature = "rustls"))]
40 pub tls_config: Option<std::sync::Arc<rustls_crate::ClientConfig>>,
41 #[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
43 #[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
44 pub tls_config: Option<std::sync::Arc<async_native_tls::TlsConnector>>,
45}
46
47impl Debug for Config {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 let mut dbg_struct = f.debug_struct("Config");
50 dbg_struct
51 .field("http_keep_alive", &self.http_keep_alive)
52 .field("tcp_no_delay", &self.tcp_no_delay)
53 .field("timeout", &self.timeout)
54 .field("max_connections_per_host", &self.max_connections_per_host);
55
56 #[cfg(all(feature = "h1_client", feature = "rustls"))]
57 {
58 if self.tls_config.is_some() {
59 dbg_struct.field("tls_config", &"Some(rustls::ClientConfig)");
60 } else {
61 dbg_struct.field("tls_config", &"None");
62 }
63 }
64 #[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
65 {
66 dbg_struct.field("tls_config", &self.tls_config);
67 }
68
69 dbg_struct.finish()
70 }
71}
72
73impl Config {
74 pub fn new() -> Self {
76 Self {
77 http_keep_alive: true,
78 tcp_no_delay: false,
79 timeout: Some(Duration::from_secs(60)),
80 max_connections_per_host: 50,
81 #[cfg(all(feature = "h1_client", any(feature = "rustls", feature = "native-tls")))]
82 tls_config: None,
83 }
84 }
85}
86
87impl Default for Config {
88 fn default() -> Self {
89 Self::new()
90 }
91}
92
93impl Config {
94 pub fn set_http_keep_alive(mut self, keep_alive: bool) -> Self {
96 self.http_keep_alive = keep_alive;
97 self
98 }
99
100 pub fn set_tcp_no_delay(mut self, no_delay: bool) -> Self {
102 self.tcp_no_delay = no_delay;
103 self
104 }
105
106 pub fn set_timeout(mut self, timeout: Option<Duration>) -> Self {
108 self.timeout = timeout;
109 self
110 }
111
112 pub fn set_max_connections_per_host(mut self, max_connections_per_host: usize) -> Self {
114 self.max_connections_per_host = max_connections_per_host;
115 self
116 }
117
118 #[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
120 #[cfg(all(feature = "h1_client", feature = "rustls"))]
121 pub fn set_tls_config(
122 mut self,
123 tls_config: Option<std::sync::Arc<rustls_crate::ClientConfig>>,
124 ) -> Self {
125 self.tls_config = tls_config;
126 self
127 }
128 #[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
130 #[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
131 pub fn set_tls_config(
132 mut self,
133 tls_config: Option<std::sync::Arc<async_native_tls::TlsConnector>>,
134 ) -> Self {
135 self.tls_config = tls_config;
136 self
137 }
138}