From a54bfc1a39bc98b9781a76247d4bb95aaae1780a Mon Sep 17 00:00:00 2001 From: CJP10 <14205938+CJP10@users.noreply.github.com> Date: Tue, 19 Mar 2019 16:23:32 -0400 Subject: [PATCH] added max_idle_per_host as an option to the builder (#473) --- src/async_impl/client.rs | 12 ++++++++++++ src/client.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 9ae6cc9..091e891 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -67,6 +67,7 @@ struct Config { #[cfg(feature = "tls")] certs_verification: bool, connect_timeout: Option, + max_idle_per_host: usize, #[cfg(feature = "tls")] identity: Option, proxies: Vec, @@ -100,6 +101,7 @@ impl ClientBuilder { #[cfg(feature = "tls")] certs_verification: true, connect_timeout: None, + max_idle_per_host: ::std::usize::MAX, proxies: Vec::new(), redirect_policy: RedirectPolicy::default(), referer: true, @@ -188,6 +190,8 @@ impl ClientBuilder { builder.http2_only(true); } + builder.max_idle_per_host(config.max_idle_per_host); + if config.http1_title_case_headers { builder.http1_title_case_headers(true); } @@ -329,6 +333,14 @@ impl ClientBuilder { self } + /// Sets the maximum idle connection per host allowed in the pool. + // + // Default is usize::MAX (no limit). + pub fn max_idle_per_host(mut self, max: usize) -> ClientBuilder { + self.config.max_idle_per_host = max; + self + } + /// Only use HTTP/2. pub fn h2_prior_knowledge(mut self) -> ClientBuilder { self.config.http2_only = true; diff --git a/src/client.rs b/src/client.rs index 83d7ad0..f4cf031 100644 --- a/src/client.rs +++ b/src/client.rs @@ -288,6 +288,13 @@ impl ClientBuilder { self } + /// Sets the maximum idle connection per host allowed in the pool. + /// + /// Default is usize::MAX (no limit). + pub fn max_idle_per_host(self, max: usize) -> ClientBuilder { + self.with_inner(move |inner| inner.max_idle_per_host(max)) + } + /// Set a timeout for only the connect phase of a `Client`. /// /// Default is `None`.