Skip to content

Commit

Permalink
Add extension read and write traits
Browse files Browse the repository at this point in the history
`tokio::io` has the handy AsyncReadExt and AsyncWriteExt traits, which
were preivously used in tests.

Now that we rely on Hyper IO, those had to be ported over.
That is done in this PR.

- AsyncReadExt -> ReadExt
- AsyncWriteExt -> WriteExt
- tokio internal Read -> ReadFut
- tokio internal Write -> WriteFut

The read timeout test is failing. I think it has to do with the `impl
Future` for `ReadFut`.
  • Loading branch information
allan2 committed Dec 1, 2023
1 parent 54b8041 commit 425b612
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 113 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ tokio = { version = "1.0.0", features = ["io-std", "io-util", "macros"] }
hyper = { version = "1.0", features = ["http1"] }
hyper-tls = "0.6"
http-body-util = "0.1"
tokio-util = { version = "0.7", features = ["io"] }
98 changes: 10 additions & 88 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;

use hyper::rt::{Read, Write};
use tokio::time::timeout;

use hyper_util::client::legacy::connect::{Connected, Connection};
use hyper::Uri;
use hyper_util::client::legacy::connect::{Connected, Connection};
use tower_service::Service;

mod stream;
Expand All @@ -31,8 +32,8 @@ pub struct TimeoutConnector<T> {
impl<T> TimeoutConnector<T>
where
T: Service<Uri> + Send,
T::Response: hyper::rt::Read + hyper::rt::Write + Send + Unpin,
T::Future: Send + 'static,
T::Response: Read + Write + Send + Unpin,
T::Future: Send + 'static,
T::Error: Into<BoxError>,
{
/// Construct a new TimeoutConnector with a given connector implementing the `Connect` trait
Expand Down Expand Up @@ -67,7 +68,7 @@ where
let read_timeout = self.read_timeout;
let write_timeout = self.write_timeout;
let connecting = self.connector.call(dst);

let fut = async move {
let mut stream = match connect_timeout {
None => {
Expand Down Expand Up @@ -132,12 +133,15 @@ where

#[cfg(test)]
mod tests {
use std::{io, error::Error};
use std::time::Duration;
use std::{error::Error, io};

use http_body_util::Empty;
use hyper::body::Bytes;
use hyper_util::{client::legacy::{connect::HttpConnector, Client}, rt::TokioExecutor};
use hyper_util::{
client::legacy::{connect::HttpConnector, Client},
rt::TokioExecutor,
};

use super::TimeoutConnector;

Expand Down Expand Up @@ -191,85 +195,3 @@ mod tests {
}
}
}


















































































Loading

0 comments on commit 425b612

Please sign in to comment.