From 454e5a123f2c27487b59ecc9e1ad87f70fc2de66 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Tue, 3 Jul 2018 10:54:22 +0200 Subject: [PATCH] fix send body confusion --- src/body.rs | 6 ++++++ src/unit.rs | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/body.rs b/src/body.rs index 4ed228f..9f6d634 100644 --- a/src/body.rs +++ b/src/body.rs @@ -53,6 +53,12 @@ pub struct SizedReader { pub reader: Box, } +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 { fn new(size: Option, reader: Box) -> Self { SizedReader { size, reader } diff --git a/src/unit.rs b/src/unit.rs index 5f018fb..a80273e 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -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);