Skip to content

Commit 7bae87f

Browse files
authored
feat: impl Connection for TokioIo (#117)
1 parent a566eb0 commit 7bae87f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/client/legacy/connect/http.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,10 @@ where
438438
}
439439
}
440440

441-
impl Connection for TokioIo<TcpStream> {
441+
impl Connection for TcpStream {
442442
fn connected(&self) -> Connected {
443443
let connected = Connected::new();
444-
if let (Ok(remote_addr), Ok(local_addr)) =
445-
(self.inner().peer_addr(), self.inner().local_addr())
446-
{
444+
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
447445
connected.extra(HttpInfo {
448446
remote_addr,
449447
local_addr,
@@ -454,6 +452,17 @@ impl Connection for TokioIo<TcpStream> {
454452
}
455453
}
456454

455+
// Implement `Connection` for generic `TokioIo<T>` so that external crates can
456+
// implement their own `HttpConnector` with `TokioIo<CustomTcpStream>`.
457+
impl<T> Connection for TokioIo<T>
458+
where
459+
T: Connection,
460+
{
461+
fn connected(&self) -> Connected {
462+
self.inner().connected()
463+
}
464+
}
465+
457466
impl HttpInfo {
458467
/// Get the remote address of the transport used.
459468
pub fn remote_addr(&self) -> SocketAddr {

0 commit comments

Comments
 (0)