feat(client): add HttpInfo::local_addr() method

This adds `local_addr` information from `TcpStream` to the `HttpInfo` struct

Closes #2767
This commit is contained in:
Devrim Şahin
2022-03-01 01:18:51 +03:00
committed by GitHub
parent ce2bfa9ea6
commit 055b4e7ea6

View File

@@ -66,6 +66,7 @@ pub struct HttpConnector<R = GaiResolver> {
#[derive(Clone, Debug)]
pub struct HttpInfo {
remote_addr: SocketAddr,
local_addr: SocketAddr,
}
#[derive(Clone)]
@@ -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
}
@@ -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! {