fix send body confusion

This commit is contained in:
Martin Algesten
2018-07-03 10:54:22 +02:00
parent 6981abb359
commit 454e5a123f
2 changed files with 14 additions and 7 deletions

View File

@@ -133,6 +133,9 @@ pub fn connect(
}
}
// send the body (which can be empty now depending on redirects)
send_body(body, unit.is_chunked, &mut stream)?;
// start reading the response to process cookies and redirects.
let mut resp = Response::from_read(&mut stream);
@@ -158,20 +161,18 @@ pub fn connect(
unit.url = new_url;
// perform the redirect differently depending on 3xx code.
return match resp.status() {
match resp.status() {
301 | 302 | 303 => {
send_body(body, unit.is_chunked, &mut stream)?;
let empty = Payload::Empty.into_read();
connect(unit, "GET", use_pooled, redirects - 1, empty)
return connect(unit, "GET", use_pooled, redirects - 1, empty);
}
307 | 308 | _ => connect(unit, method, use_pooled, redirects - 1, body),
, _ => (),
// reinstate this with expect-100
// 307 | 308 | _ => connect(unit, method, use_pooled, redirects - 1, body),
};
}
}
// send the body (which can be empty now depending on redirects)
send_body(body, unit.is_chunked, &mut stream)?;
// since it is not a redirect, give away the incoming stream to the response object
response::set_stream(&mut resp, Some(unit), stream);