Skip to content

Commit a268be7

Browse files
committed
refactor: share the H1Client Config via an Arc
1 parent 2740e26 commit a268be7

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/h1/mod.rs

Lines changed: 7 additions & 6 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 {
@@ -104,7 +105,7 @@ impl H1Client {
104105
#[cfg(any(feature = "native-tls", feature = "rustls"))]
105106
https_pools: DashMap::new(),
106107
max_concurrent_connections: DEFAULT_MAX_CONCURRENT_CONNECTIONS,
107-
config: Config::default(),
108+
config: Arc::new(Config::default()),
108109
}
109110
}
110111

@@ -115,7 +116,7 @@ impl H1Client {
115116
#[cfg(any(feature = "native-tls", feature = "rustls"))]
116117
https_pools: DashMap::new(),
117118
max_concurrent_connections: max,
118-
config: Config::default(),
119+
config: Arc::new(Config::default()),
119120
}
120121
}
121122
}
@@ -276,15 +277,15 @@ impl HttpClient for H1Client {
276277
///
277278
/// Config options may not impact existing connections.
278279
fn set_config(&mut self, config: Config) -> http_types::Result<()> {
279-
self.config = config;
280+
self.config = Arc::new(config);
280281

281282
Ok(())
282283
}
283284

284285
#[cfg(feature = "unstable-config")]
285286
/// Get the current configuration.
286287
fn config(&self) -> &Config {
287-
&self.config
288+
&*self.config
288289
}
289290
}
290291

@@ -298,7 +299,7 @@ impl TryFrom<Config> for H1Client {
298299
#[cfg(any(feature = "native-tls", feature = "rustls"))]
299300
https_pools: DashMap::new(),
300301
max_concurrent_connections: DEFAULT_MAX_CONCURRENT_CONNECTIONS,
301-
config,
302+
config: Arc::new(config),
302303
})
303304
}
304305
}

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)