Skip to content

Commit

Permalink
Remove client builder
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
  • Loading branch information
kckeiks committed Aug 13, 2022
1 parent 26a14b8 commit 35ed469
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
14 changes: 5 additions & 9 deletions src/async_impl/client.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 7 additions & 25 deletions src/async_impl/h3_client/mod.rs
Expand Up @@ -17,38 +17,20 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;

pub(crate) struct H3Builder {
pool_idle_timeout: Option<Duration>,
}

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<Duration>) {
self.pool_idle_timeout = timeout;
}
}

#[derive(Clone)]
pub(crate) struct H3Client {
pool: Pool,
connector: H3Connector,
}

impl H3Client {
pub fn new(connector: H3Connector, pool_timeout: Option<Duration>) -> Self {
H3Client {
pool: Pool::new(pool_timeout),
connector,
}
}

async fn get_pooled_client(&mut self, key: Key) -> Result<PoolClient, BoxError> {
if let Some(client) = self.pool.try_pool(&key) {
trace!("getting client from pool with key {:?}", key);
Expand Down

0 comments on commit 35ed469

Please sign in to comment.