Apply deadline across redirects. (#313)
Previously, each redirect could take timeout time, so a series of slow redirects could run for longer than expected, or indefinitely.
This commit is contained in:
committed by
GitHub
parent
d627ef9704
commit
b246f0a9d2
@@ -1,6 +1,8 @@
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
net::TcpStream,
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use testserver::{self, TestServer};
|
||||
|
||||
@@ -158,6 +160,31 @@ fn redirect_308() {
|
||||
assert_eq!(resp.get_url(), "test://host/valid_response");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redirects_hit_timeout() {
|
||||
// A chain of 2 redirects and an OK, each of which takes 50ms; we set a
|
||||
// timeout of 100ms and should error.
|
||||
test::set_handler("/redirect_sleep1", |_| {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
test::make_response(302, "Go here", vec!["Location: /redirect_sleep2"], vec![])
|
||||
});
|
||||
test::set_handler("/redirect_sleep2", |_| {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
test::make_response(302, "Go here", vec!["Location: /ok"], vec![])
|
||||
});
|
||||
test::set_handler("/ok", |_| {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
test::make_response(200, "Go here", vec![], vec![])
|
||||
});
|
||||
let req = crate::builder().timeout(Duration::from_millis(100)).build();
|
||||
let result = req.get("test://host/redirect_sleep1").call();
|
||||
assert!(
|
||||
matches!(result, Err(Error::Transport(_))),
|
||||
"expected Transport error, got {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_many_redirects() {
|
||||
for i in 0..10_000 {
|
||||
|
||||
Reference in New Issue
Block a user