Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local_addr information from TcpStream to the HttpInfo struct #2768

Merged
merged 1 commit into from Feb 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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