Skip to content

Commit

Permalink
feat: impl Connection for TokioIo (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Apr 14, 2024
1 parent a566eb0 commit 7bae87f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/client/legacy/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,10 @@ where
}
}

impl Connection for TokioIo<TcpStream> {
impl Connection for TcpStream {
fn connected(&self) -> Connected {
let connected = Connected::new();
if let (Ok(remote_addr), Ok(local_addr)) =
(self.inner().peer_addr(), self.inner().local_addr())
{
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
connected.extra(HttpInfo {
remote_addr,
local_addr,
Expand All @@ -454,6 +452,17 @@ impl Connection for TokioIo<TcpStream> {
}
}

// Implement `Connection` for generic `TokioIo<T>` so that external crates can
// implement their own `HttpConnector` with `TokioIo<CustomTcpStream>`.
impl<T> Connection for TokioIo<T>
where
T: Connection,
{
fn connected(&self) -> Connected {
self.inner().connected()
}
}

impl HttpInfo {
/// Get the remote address of the transport used.
pub fn remote_addr(&self) -> SocketAddr {
Expand Down

0 comments on commit 7bae87f

Please sign in to comment.