use std::fmt::Debug;
use std::time::Duration;
#[non_exhaustive]
#[derive(Clone)]
pub struct Config {
pub http_keep_alive: bool,
pub tcp_no_delay: bool,
pub timeout: Option<Duration>,
pub max_connections_per_host: usize,
#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
#[cfg(all(feature = "h1_client", feature = "rustls"))]
pub tls_config: Option<std::sync::Arc<rustls::ClientConfig>>,
#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
#[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
pub tls_config: Option<std::sync::Arc<async_native_tls::TlsConnector>>,
}
impl Debug for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut dbg_struct = f.debug_struct("Config");
dbg_struct
.field("http_keep_alive", &self.http_keep_alive)
.field("tcp_no_delay", &self.tcp_no_delay)
.field("timeout", &self.timeout)
.field("max_connections_per_host", &self.max_connections_per_host);
#[cfg(all(feature = "h1_client", feature = "rustls"))]
{
if self.tls_config.is_some() {
dbg_struct.field("tls_config", &"Some(rustls::ClientConfig)");
} else {
dbg_struct.field("tls_config", &"None");
}
}
#[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
{
dbg_struct.field("tls_config", &self.tls_config);
}
dbg_struct.finish()
}
}
impl Config {
pub fn new() -> Self {
Self {
http_keep_alive: true,
tcp_no_delay: false,
timeout: Some(Duration::from_secs(60)),
max_connections_per_host: 50,
#[cfg(all(feature = "h1_client", any(feature = "rustls", feature = "native-tls")))]
tls_config: None,
}
}
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}
impl Config {
pub fn set_http_keep_alive(mut self, keep_alive: bool) -> Self {
self.http_keep_alive = keep_alive;
self
}
pub fn set_tcp_no_delay(mut self, no_delay: bool) -> Self {
self.tcp_no_delay = no_delay;
self
}
pub fn set_timeout(mut self, timeout: Option<Duration>) -> Self {
self.timeout = timeout;
self
}
pub fn set_max_connections_per_host(mut self, max_connections_per_host: usize) -> Self {
self.max_connections_per_host = max_connections_per_host;
self
}
#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
#[cfg(all(feature = "h1_client", feature = "rustls"))]
pub fn set_tls_config(
mut self,
tls_config: Option<std::sync::Arc<rustls::ClientConfig>>,
) -> Self {
self.tls_config = tls_config;
self
}
#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
#[cfg(all(feature = "h1_client", feature = "native-tls", not(feature = "rustls")))]
pub fn set_tls_config(
mut self,
tls_config: Option<std::sync::Arc<async_native_tls::TlsConnector>>,
) -> Self {
self.tls_config = tls_config;
self
}
}