From 35ed469d72fc5ca755142df9eb85f271edb2379c Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Sat, 13 Aug 2022 19:11:55 -0400 Subject: [PATCH] Remove client builder Signed-off-by: Miguel Guarniz --- src/async_impl/client.rs | 14 +++++--------- src/async_impl/h3_client/mod.rs | 32 +++++++------------------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 1b0d3adcd..504c1b256 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -31,7 +31,7 @@ use crate::async_impl::h3_client::connect::H3Connector; #[cfg(feature = "http3")] use crate::async_impl::h3_client::dns::Resolver; #[cfg(feature = "http3")] -use crate::async_impl::h3_client::{H3Builder, H3Client, H3ResponseFuture}; +use crate::async_impl::h3_client::{H3Client, H3ResponseFuture}; use crate::connect::{Connector, HttpConnector}; #[cfg(feature = "cookies")] use crate::cookie; @@ -599,20 +599,16 @@ impl ClientBuilder { let proxies_maybe_http_auth = proxies.iter().any(|p| p.maybe_has_http_auth()); - #[cfg(feature = "http3")] - let h3_builder = { - let mut h3_builder = H3Builder::default(); - h3_builder.set_pool_idle_timeout(config.pool_idle_timeout); - h3_builder - }; - Ok(Client { inner: Arc::new(ClientRef { accepts: config.accepts, #[cfg(feature = "cookies")] cookie_store: config.cookie_store, #[cfg(feature = "http3")] - h3_client: h3_builder.build(h3_connector.expect("missing HTTP/3 connector")), + h3_client: H3Client::new( + h3_connector.expect("missing HTTP/3 connector"), + config.pool_idle_timeout, + ), hyper: builder.build(connector), headers: config.headers, redirect_policy: config.redirect_policy, diff --git a/src/async_impl/h3_client/mod.rs b/src/async_impl/h3_client/mod.rs index ec85ba6e4..59e3a7667 100644 --- a/src/async_impl/h3_client/mod.rs +++ b/src/async_impl/h3_client/mod.rs @@ -17,31 +17,6 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -pub(crate) struct H3Builder { - pool_idle_timeout: Option, -} - -impl Default for H3Builder { - fn default() -> Self { - Self { - pool_idle_timeout: Some(Duration::from_secs(90)), - } - } -} - -impl H3Builder { - pub fn build(self, connector: H3Connector) -> H3Client { - H3Client { - pool: Pool::new(self.pool_idle_timeout), - connector, - } - } - - pub fn set_pool_idle_timeout(&mut self, timeout: Option) { - self.pool_idle_timeout = timeout; - } -} - #[derive(Clone)] pub(crate) struct H3Client { pool: Pool, @@ -49,6 +24,13 @@ pub(crate) struct H3Client { } impl H3Client { + pub fn new(connector: H3Connector, pool_timeout: Option) -> Self { + H3Client { + pool: Pool::new(pool_timeout), + connector, + } + } + async fn get_pooled_client(&mut self, key: Key) -> Result { if let Some(client) = self.pool.try_pool(&key) { trace!("getting client from pool with key {:?}", key);