Skip to content

Commit 425b612

Browse files
committed
Add extension read and write traits
`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`.
1 parent 54b8041 commit 425b612

File tree

3 files changed

+171
-113
lines changed

3 files changed

+171
-113
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ tokio = { version = "1.0.0", features = ["io-std", "io-util", "macros"] }
2222
hyper = { version = "1.0", features = ["http1"] }
2323
hyper-tls = "0.6"
2424
http-body-util = "0.1"
25+
tokio-util = { version = "0.7", features = ["io"] }

src/lib.rs

+10-88
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use std::pin::Pin;
44
use std::task::{Context, Poll};
55
use std::time::Duration;
66

7+
use hyper::rt::{Read, Write};
78
use tokio::time::timeout;
89

9-
use hyper_util::client::legacy::connect::{Connected, Connection};
1010
use hyper::Uri;
11+
use hyper_util::client::legacy::connect::{Connected, Connection};
1112
use tower_service::Service;
1213

1314
mod stream;
@@ -31,8 +32,8 @@ pub struct TimeoutConnector<T> {
3132
impl<T> TimeoutConnector<T>
3233
where
3334
T: Service<Uri> + Send,
34-
T::Response: hyper::rt::Read + hyper::rt::Write + Send + Unpin,
35-
T::Future: Send + 'static,
35+
T::Response: Read + Write + Send + Unpin,
36+
T::Future: Send + 'static,
3637
T::Error: Into<BoxError>,
3738
{
3839
/// Construct a new TimeoutConnector with a given connector implementing the `Connect` trait
@@ -67,7 +68,7 @@ where
6768
let read_timeout = self.read_timeout;
6869
let write_timeout = self.write_timeout;
6970
let connecting = self.connector.call(dst);
70-
71+
7172
let fut = async move {
7273
let mut stream = match connect_timeout {
7374
None => {
@@ -132,12 +133,15 @@ where
132133

133134
#[cfg(test)]
134135
mod tests {
135-
use std::{io, error::Error};
136136
use std::time::Duration;
137+
use std::{error::Error, io};
137138

138139
use http_body_util::Empty;
139140
use hyper::body::Bytes;
140-
use hyper_util::{client::legacy::{connect::HttpConnector, Client}, rt::TokioExecutor};
141+
use hyper_util::{
142+
client::legacy::{connect::HttpConnector, Client},
143+
rt::TokioExecutor,
144+
};
141145

142146
use super::TimeoutConnector;
143147

@@ -191,85 +195,3 @@ mod tests {
191195
}
192196
}
193197
}
194-
195-
196-
197-
198-
199-
200-
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-
214-
215-
216-
217-
218-
219-
220-
221-
222-
223-
224-
225-
226-
227-
228-
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247-
248-
249-
250-
251-
252-
253-
254-
255-
256-
257-
258-
259-
260-
261-
262-
263-
264-
265-
266-
267-
268-
269-
270-
271-
272-
273-
274-
275-

0 commit comments

Comments
 (0)