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:
Jacob Hoffman-Andrews
2021-02-07 12:29:35 -08:00
committed by GitHub
parent d627ef9704
commit b246f0a9d2
3 changed files with 53 additions and 11 deletions

View File

@@ -38,6 +38,7 @@ impl Unit {
url: &Url,
headers: &Vec<Header>,
body: &SizedReader,
deadline: Option<time::Instant>,
) -> Self {
//
@@ -99,14 +100,6 @@ impl Unit {
.cloned()
.collect();
let deadline = match agent.config.timeout {
None => None,
Some(timeout) => {
let now = time::Instant::now();
Some(now.checked_add(timeout).unwrap())
}
};
Unit {
agent: agent.clone(),
method: method.to_string(),
@@ -213,7 +206,14 @@ pub(crate) fn connect(
history.push(unit.url.to_string());
body = Payload::Empty.into_read();
// recreate the unit to get a new hostname and cookies for the new host.
unit = Unit::new(&unit.agent, &new_method, &new_url, &unit.headers, &body);
unit = Unit::new(
&unit.agent,
&new_method,
&new_url,
&unit.headers,
&body,
unit.deadline,
);
};
resp.history = history;
Ok(resp)