Skip to content

Commit 055b4e7

Browse files
authoredFeb 28, 2022
feat(client): add HttpInfo::local_addr() method
This adds `local_addr` information from `TcpStream` to the `HttpInfo` struct Closes #2767
1 parent ce2bfa9 commit 055b4e7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎src/client/connect/http.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub struct HttpConnector<R = GaiResolver> {
6666
#[derive(Clone, Debug)]
6767
pub struct HttpInfo {
6868
remote_addr: SocketAddr,
69+
local_addr: SocketAddr,
6970
}
7071

7172
#[derive(Clone)]
@@ -360,8 +361,8 @@ where
360361
impl Connection for TcpStream {
361362
fn connected(&self) -> Connected {
362363
let connected = Connected::new();
363-
if let Ok(remote_addr) = self.peer_addr() {
364-
connected.extra(HttpInfo { remote_addr })
364+
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
365+
connected.extra(HttpInfo { remote_addr, local_addr })
365366
} else {
366367
connected
367368
}
@@ -373,6 +374,11 @@ impl HttpInfo {
373374
pub fn remote_addr(&self) -> SocketAddr {
374375
self.remote_addr
375376
}
377+
378+
/// Get the local address of the transport used.
379+
pub fn local_addr(&self) -> SocketAddr {
380+
self.local_addr
381+
}
376382
}
377383

378384
pin_project! {

0 commit comments

Comments
 (0)
Please sign in to comment.