Skip to content

Commit

Permalink
feat(client): add HttpInfo::local_addr() method
Browse files Browse the repository at this point in the history
This adds `local_addr` information from `TcpStream` to the `HttpInfo` struct

Closes #2767
  • Loading branch information
kubuzetto committed Feb 28, 2022
1 parent ce2bfa9 commit 055b4e7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/client/connect/http.rs
Expand Up @@ -66,6 +66,7 @@ pub struct HttpConnector<R = GaiResolver> {
#[derive(Clone, Debug)]
pub struct HttpInfo {
remote_addr: SocketAddr,
local_addr: SocketAddr,
}

#[derive(Clone)]
Expand Down Expand Up @@ -360,8 +361,8 @@ where
impl Connection for TcpStream {
fn connected(&self) -> Connected {
let connected = Connected::new();
if let Ok(remote_addr) = self.peer_addr() {
connected.extra(HttpInfo { remote_addr })
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
connected.extra(HttpInfo { remote_addr, local_addr })
} else {
connected
}
Expand All @@ -373,6 +374,11 @@ impl HttpInfo {
pub fn remote_addr(&self) -> SocketAddr {
self.remote_addr
}

/// Get the local address of the transport used.
pub fn local_addr(&self) -> SocketAddr {
self.local_addr
}
}

pin_project! {
Expand Down

0 comments on commit 055b4e7

Please sign in to comment.