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:
@@ -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! {
|
||||
|
||||
Reference in New Issue
Block a user