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

@@ -53,6 +53,12 @@ pub struct SizedReader {
pub reader: Box<dyn Read + 'static>, pub reader: Box<dyn Read + 'static>,
} }
impl ::std::fmt::Debug for SizedReader {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
write!(f, "SizedReader[size={:?},reader]", self.size)
}
}
impl SizedReader { impl SizedReader {
fn new(size: Option<usize>, reader: Box<dyn Read + 'static>) -> Self { fn new(size: Option<usize>, reader: Box<dyn Read + 'static>) -> Self {
SizedReader { size, reader } SizedReader { size, reader }

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. // start reading the response to process cookies and redirects.
let mut resp = Response::from_read(&mut stream); let mut resp = Response::from_read(&mut stream);
@@ -158,20 +161,18 @@ pub fn connect(
unit.url = new_url; unit.url = new_url;
// perform the redirect differently depending on 3xx code. // perform the redirect differently depending on 3xx code.
return match resp.status() { match resp.status() {
301 | 302 | 303 => { 301 | 302 | 303 => {
send_body(body, unit.is_chunked, &mut stream)?;
let empty = Payload::Empty.into_read(); 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 // since it is not a redirect, give away the incoming stream to the response object
response::set_stream(&mut resp, Some(unit), stream); response::set_stream(&mut resp, Some(unit), stream);