Implement option to set num of DNS threads in async ClientBuilder

This commit is contained in:
Ömer Sinan Ağacan
2017-10-08 12:30:14 +03:00
parent 01e0a144e9
commit d9d92b7479
2 changed files with 14 additions and 9 deletions

View File

@@ -69,6 +69,7 @@ struct Config {
referer: bool,
timeout: Option<Duration>,
tls: TlsConnectorBuilder,
dns_threads: usize,
}
impl ClientBuilder {
@@ -84,6 +85,7 @@ impl ClientBuilder {
referer: true,
timeout: None,
tls: tls_connector_builder,
dns_threads: 4,
}),
err: None,
},
@@ -116,7 +118,7 @@ impl ClientBuilder {
let proxies = Arc::new(config.proxies);
let mut connector = Connector::new(tls, proxies.clone(), handle);
let mut connector = Connector::new(config.dns_threads, tls, proxies.clone(), handle);
if !config.hostname_verification {
connector.danger_disable_hostname_verification();
}
@@ -237,6 +239,15 @@ impl ClientBuilder {
}
self
}
/// Set number of DNS threads.
#[inline]
pub fn dns_threads(&mut self, threads: usize) -> &mut ClientBuilder {
if let Some(config) = config_mut(&mut self.config, &self.err) {
config.dns_threads = threads;
}
self
}
}
fn config_mut<'a>(config: &'a mut Option<Config>, err: &Option<::Error>) -> Option<&'a mut Config> {
@@ -249,12 +260,6 @@ fn config_mut<'a>(config: &'a mut Option<Config>, err: &Option<::Error>) -> Opti
type HyperClient = ::hyper::Client<Connector>;
fn create_hyper_client(tls: TlsConnector, proxies: Arc<Vec<Proxy>>, handle: &Handle) -> HyperClient {
::hyper::Client::configure()
.connector(Connector::new(tls, proxies, handle))
.build(handle)
}
impl Client {
/// Constructs a new `Client`.
///