Reinstate read timeouts on body.
This feature was broken in #67, which reset timeouts on the stream before passing it to set_stream. As part of this change, refactor the internal storage of timeouts on the Request object to use Option<Duration>. Remove the deadline field on Response. It wasn't used. The deadline field on unit was used instead. Add a unittest.
This commit is contained in:
committed by
Martin Algesten
parent
32f9ebc04a
commit
2bf9362eff
@@ -19,7 +19,7 @@ fn dribble_body_respond(mut stream: TcpStream, contents: &[u8]) -> io::Result<()
|
||||
stream.write_all(&contents[i..i + 1])?;
|
||||
stream.write_all(&[b'\n'; 1])?;
|
||||
stream.flush()?;
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -47,6 +47,22 @@ fn overall_timeout_during_body() {
|
||||
get_and_expect_timeout(url);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_timeout_during_body() {
|
||||
let server = TestServer::new(|stream| dribble_body_respond(stream, &[b'a'; 300]));
|
||||
let url = format!("http://localhost:{}/", server.port);
|
||||
let agent = Agent::default().build();
|
||||
let resp = agent.get(&url).timeout_read(5).call();
|
||||
match resp.into_string() {
|
||||
Err(io_error) => match io_error.kind() {
|
||||
io::ErrorKind::TimedOut => Ok(()),
|
||||
_ => Err(format!("{:?}", io_error)),
|
||||
},
|
||||
Ok(_) => Err("successful response".to_string()),
|
||||
}
|
||||
.expect("expected timeout but got something else");
|
||||
}
|
||||
|
||||
// Send HTTP headers on the TcpStream at a rate of one header every 100
|
||||
// milliseconds, for a total of 30 headers.
|
||||
fn dribble_headers_respond(mut stream: TcpStream) -> io::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user