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,5 +1,5 @@
|
||||
use std::fmt;
|
||||
use std::io::Read;
|
||||
use std::{fmt, time};
|
||||
|
||||
use url::{form_urlencoded, Url};
|
||||
|
||||
@@ -116,8 +116,23 @@ impl Request {
|
||||
for (name, value) in self.query_params.clone() {
|
||||
url.query_pairs_mut().append_pair(&name, &value);
|
||||
}
|
||||
let deadline = match self.agent.config.timeout {
|
||||
None => None,
|
||||
Some(timeout) => {
|
||||
let now = time::Instant::now();
|
||||
Some(now.checked_add(timeout).unwrap())
|
||||
}
|
||||
};
|
||||
|
||||
let reader = payload.into_read();
|
||||
let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader);
|
||||
let unit = Unit::new(
|
||||
&self.agent,
|
||||
&self.method,
|
||||
&url,
|
||||
&self.headers,
|
||||
&reader,
|
||||
deadline,
|
||||
);
|
||||
let response = unit::connect(unit, true, reader).map_err(|e| e.url(url.clone()))?;
|
||||
|
||||
if response.status() >= 400 {
|
||||
|
||||
Reference in New Issue
Block a user