Repository: seanmonstar/reqwest (language: rust)

Issue:
Invalid headers while redirecting
https://github.com/seanmonstar/reqwest/blob/a205128f038431e37bfff25ade4ff04d20e7dd32/src/async_impl/client.rs#L447-L458

After having post request with some data and receiving FOUND 302 from server
body is erased, but data headers are left intact leading to malformed HTTP request.




Discussion / hints:

Fix patch:
diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs
index 0e5a0e7e0..bdf738cc9 100644
--- a/src/async_impl/client.rs
+++ b/src/async_impl/client.rs
@@ -6,7 +6,7 @@ use bytes::Bytes;
 use futures::{Async, Future, Poll};
 use hyper::client::ResponseFuture;
 use header::{HeaderMap, HeaderValue, LOCATION, USER_AGENT, REFERER, ACCEPT,
-             ACCEPT_ENCODING, RANGE};
+             ACCEPT_ENCODING, RANGE, TRANSFER_ENCODING, CONTENT_TYPE, CONTENT_LENGTH, CONTENT_ENCODING};
 use mime::{self};
 use native_tls::{TlsConnector, TlsConnectorBuilder};
 
@@ -454,6 +454,10 @@ impl Future for PendingRequest {
                 StatusCode::FOUND |
                 StatusCode::SEE_OTHER => {
                     self.body = None;
+                    for header in &[TRANSFER_ENCODING, CONTENT_ENCODING, CONTENT_TYPE, CONTENT_LENGTH] {
+                        self.headers.remove(header);
+                    }
+
                     match self.method {
                         Method::GET | Method::HEAD => {},
                         _ => {


Test patch: