Skip to content

Commit b6283c6

Browse files
committed
refactor: remove Arc in h1
This now serves no purpose. (If it ever did?)
1 parent bc3b903 commit b6283c6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/h1/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! http-client implementation for async-h1, with connecton pooling ("Keep-Alive").
22
3+
use std::fmt::Debug;
34
use std::net::SocketAddr;
4-
use std::{fmt::Debug, sync::Arc};
55

66
use async_h1::client;
77
use async_std::net::TcpStream;
@@ -31,8 +31,8 @@ type HttpsPool = DashMap<SocketAddr, Pool<TlsStream<TcpStream>, Error>>;
3131

3232
/// Async-h1 based HTTP Client, with connecton pooling ("Keep-Alive").
3333
pub struct H1Client {
34-
http_pools: Arc<HttpPool>,
35-
https_pools: Arc<HttpsPool>,
34+
http_pools: HttpPool,
35+
https_pools: HttpsPool,
3636
}
3737

3838
impl Debug for H1Client {
@@ -51,17 +51,15 @@ impl H1Client {
5151
/// Create a new instance.
5252
pub fn new() -> Self {
5353
Self {
54-
http_pools: Arc::new(DashMap::new()),
55-
https_pools: Arc::new(DashMap::new()),
54+
http_pools: DashMap::new(),
55+
https_pools: DashMap::new(),
5656
}
5757
}
5858
}
5959

6060
#[async_trait]
6161
impl HttpClient for H1Client {
6262
async fn send(&self, mut req: Request) -> Result<Response, Error> {
63-
let http_pools = self.http_pools.clone();
64-
let https_pools = self.https_pools.clone();
6563
req.insert_header("Connection", "keep-alive");
6664

6765
// Insert host
@@ -94,14 +92,14 @@ impl HttpClient for H1Client {
9492

9593
match scheme {
9694
"http" => {
97-
let pool = if let Some(pool) = http_pools.get(&addr) {
95+
let pool = if let Some(pool) = self.http_pools.get(&addr) {
9896
pool
9997
} else {
10098
let manager = TcpConnection::new(addr);
10199
let pool =
102100
Pool::<TcpStream, std::io::Error>::new(manager, MAX_CONCURRENT_CONNECTIONS);
103-
http_pools.insert(addr, pool);
104-
http_pools.get(&addr).unwrap()
101+
self.http_pools.insert(addr, pool);
102+
self.http_pools.get(&addr).unwrap()
105103
};
106104
let pool = pool.clone();
107105
let stream = pool.get().await?;
@@ -115,16 +113,16 @@ impl HttpClient for H1Client {
115113
// client::connect(stream, req).await
116114
}
117115
"https" => {
118-
let pool = if let Some(pool) = https_pools.get(&addr) {
116+
let pool = if let Some(pool) = self.https_pools.get(&addr) {
119117
pool
120118
} else {
121119
let manager = TlsConnection::new(host.clone(), addr);
122120
let pool = Pool::<TlsStream<TcpStream>, Error>::new(
123121
manager,
124122
MAX_CONCURRENT_CONNECTIONS,
125123
);
126-
https_pools.insert(addr, pool);
127-
https_pools.get(&addr).unwrap()
124+
self.https_pools.insert(addr, pool);
125+
self.https_pools.get(&addr).unwrap()
128126
};
129127
let pool = pool.clone();
130128
let stream = pool.get().await.unwrap(); // TODO: remove unwrap

0 commit comments

Comments
 (0)