Skip to content

Commit 0bc9585

Browse files
committed
feat: better debug struct for H1Client
Better debug info for connection pooling.
1 parent 60e351b commit 0bc9585

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

examples/debug_h1_client.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![cfg(feature = "h1_client")]
2+
3+
use http_client::{h1::H1Client, HttpClient};
4+
use http_types::{Method, Request};
5+
6+
#[async_std::main]
7+
async fn main() {
8+
let client = H1Client::new();
9+
10+
let req = Request::new(Method::Get, "http://example.org");
11+
12+
client.send(req).await.unwrap();
13+
14+
dbg!(client);
15+
}

src/h1/mod.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,40 @@ pub struct H1Client {
3737

3838
impl Debug for H1Client {
3939
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40-
f.write_str("H1Client")
40+
f.debug_struct("H1Client")
41+
.field(
42+
"http_pools",
43+
&self
44+
.http_pools
45+
.iter()
46+
.map(|pool| {
47+
let status = pool.status();
48+
format!(
49+
"Connections: {}, Available: {}, Max: {}",
50+
status.size, status.available, status.max_size
51+
)
52+
})
53+
.collect::<Vec<String>>(),
54+
)
55+
.field(
56+
"https_pools",
57+
&self
58+
.http_pools
59+
.iter()
60+
.map(|pool| {
61+
let status = pool.status();
62+
format!(
63+
"Connections: {}, Available: {}, Max: {}",
64+
status.size, status.available, status.max_size
65+
)
66+
})
67+
.collect::<Vec<String>>(),
68+
)
69+
.field(
70+
"max_concurrent_connections",
71+
&self.max_concurrent_connections,
72+
)
73+
.finish()
4174
}
4275
}
4376

0 commit comments

Comments
 (0)