Skip to content

Commit d4fad65

Browse files
committed
refactor: share the H1Client Config via an Arc
1 parent fdeb74b commit d4fad65

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/h1/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::convert::{Infallible, TryFrom};
55

66
use std::fmt::Debug;
77
use std::net::SocketAddr;
8+
use std::sync::Arc;
89

910
use async_h1::client;
1011
use async_std::net::TcpStream;
@@ -45,7 +46,7 @@ pub struct H1Client {
4546
#[cfg(any(feature = "native-tls", feature = "rustls"))]
4647
https_pools: HttpsPool,
4748
max_concurrent_connections: usize,
48-
config: Config,
49+
config: Arc<Config>,
4950
}
5051

5152
impl Debug for H1Client {
@@ -89,7 +90,7 @@ impl Debug for H1Client {
8990

9091
#[cfg(not(feature = "rustls"))]
9192
{
92-
dbg_struct.field("config", &self.config);
93+
dbg_struct.field("config", &*self.config);
9394
}
9495

9596
dbg_struct.finish()
@@ -110,7 +111,7 @@ impl H1Client {
110111
#[cfg(any(feature = "native-tls", feature = "rustls"))]
111112
https_pools: DashMap::new(),
112113
max_concurrent_connections: DEFAULT_MAX_CONCURRENT_CONNECTIONS,
113-
config: Config::default(),
114+
config: Arc::new(Config::default()),
114115
}
115116
}
116117

@@ -121,7 +122,7 @@ impl H1Client {
121122
#[cfg(any(feature = "native-tls", feature = "rustls"))]
122123
https_pools: DashMap::new(),
123124
max_concurrent_connections: max,
124-
config: Config::default(),
125+
config: Arc::new(Config::default()),
125126
}
126127
}
127128
}
@@ -282,15 +283,15 @@ impl HttpClient for H1Client {
282283
///
283284
/// Config options may not impact existing connections.
284285
fn set_config(&mut self, config: Config) -> http_types::Result<()> {
285-
self.config = config;
286+
self.config = Arc::new(config);
286287

287288
Ok(())
288289
}
289290

290291
#[cfg(feature = "unstable-config")]
291292
/// Get the current configuration.
292293
fn config(&self) -> &Config {
293-
&self.config
294+
&*self.config
294295
}
295296
}
296297

@@ -304,7 +305,7 @@ impl TryFrom<Config> for H1Client {
304305
#[cfg(any(feature = "native-tls", feature = "rustls"))]
305306
https_pools: DashMap::new(),
306307
max_concurrent_connections: DEFAULT_MAX_CONCURRENT_CONNECTIONS,
307-
config,
308+
config: Arc::new(config),
308309
})
309310
}
310311
}

src/h1/tcp.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::net::SocketAddr;
22
use std::pin::Pin;
3+
use std::sync::Arc;
34

45
use async_std::net::TcpStream;
56
use async_trait::async_trait;
@@ -13,11 +14,11 @@ use crate::Config;
1314
#[cfg_attr(not(feature = "rustls"), derive(std::fmt::Debug))]
1415
pub(crate) struct TcpConnection {
1516
addr: SocketAddr,
16-
config: Config,
17+
config: Arc<Config>,
1718
}
1819

1920
impl TcpConnection {
20-
pub(crate) fn new(addr: SocketAddr, config: Config) -> Self {
21+
pub(crate) fn new(addr: SocketAddr, config: Arc<Config>) -> Self {
2122
Self { addr, config }
2223
}
2324
}

src/h1/tls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::net::SocketAddr;
22
use std::pin::Pin;
3+
use std::sync::Arc;
34

45
use async_std::net::TcpStream;
56
use async_trait::async_trait;
@@ -22,11 +23,11 @@ use crate::{Config, Error};
2223
pub(crate) struct TlsConnection {
2324
host: String,
2425
addr: SocketAddr,
25-
config: Config,
26+
config: Arc<Config>,
2627
}
2728

2829
impl TlsConnection {
29-
pub(crate) fn new(host: String, addr: SocketAddr, config: Config) -> Self {
30+
pub(crate) fn new(host: String, addr: SocketAddr, config: Arc<Config>) -> Self {
3031
Self { host, addr, config }
3132
}
3233
}

0 commit comments

Comments
 (0)