Avoids sending a request body on a redirect

This commit is contained in:
Sam Gibson 2015-08-15 22:10:52 +10:00
parent 15d82091c5
commit 3c756d254b
2 changed files with 75 additions and 6 deletions

View file

@ -433,12 +433,22 @@ pub fn load<A>(mut load_data: LoadData,
info!("{:?}", load_data.data);
}
// TODO: Avoid automatically sending request body if a redirect has occurred.
if let Some(ref data) = load_data.data {
req.headers_mut().set(ContentLength(data.len() as u64));
}
let response = try!(req.send(&load_data.data));
// Avoid automatically sending request body if a redirect has occurred.
//
// TODO - This is the wrong behaviour according to the RFC. However, I'm not
// sure how much "correctness" vs. real-world is important in this case.
//
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
let is_redirected_request = iters != 1;
let response = match load_data.data {
Some(ref data) if !is_redirected_request => {
req.headers_mut().set(ContentLength(data.len() as u64));
try!(req.send(&load_data.data))
}
_ => {
try!(req.send(&None))
}
};
// --- Tell devtools we've made a request
// Send an HttpRequest message to devtools with a unique request_id