Browse Source

Remove Transfer-Encoding headers when proxying

This fixes some issues where the client expects a chunked response but
doesn't get one.
Thomas Dy 7 years ago
parent
commit
c6109a561d
1 changed files with 4 additions and 1 deletions
  1. 4 1
      rust-server/src/handler.rs

+ 4 - 1
rust-server/src/handler.rs

@@ -5,7 +5,7 @@ use std::io::Read;
 use hyper::{Get, Post};
 use hyper::Client;
 use hyper::client;
-use hyper::header::{ContentType, ETag, EntityTag, IfNoneMatch, Headers};
+use hyper::header::{ContentType, ETag, EntityTag, IfNoneMatch, Headers, TransferEncoding};
 use hyper::server::{Handler, Request, Response};
 use hyper::status::StatusCode::{InternalServerError, NotFound, NotModified, Unauthorized};
 use hyper::uri::RequestUri::AbsolutePath;
@@ -34,6 +34,7 @@ impl SiteHandler {
     fn post(&self, body: &str) -> client::Response {
         let mut headers = Headers::new();
         headers.set(ContentType::form_url_encoded());
+        headers.remove::<TransferEncoding>();
         self.client
             .post(API_ENDPOINT)
             .headers(headers)
@@ -130,6 +131,7 @@ impl Handler for SiteHandler {
                                     });
 
                                 res.headers_mut().extend(proxy_res.headers.iter());
+                                res.headers_mut().remove::<TransferEncoding>();
 
                                 let json = json::encode(&body).unwrap();
                                 res.send(json.as_bytes()).unwrap();
@@ -145,6 +147,7 @@ impl Handler for SiteHandler {
                         let form_data = form_urlencoded::serialize(&params);
                         let mut proxy_res = self.post(&form_data);
                         res.headers_mut().extend(proxy_res.headers.iter());
+                        res.headers_mut().remove::<TransferEncoding>();
                         let mut res = res.start().unwrap();
                         io::copy(&mut proxy_res, &mut res).ok().expect("Failed to proxy");
                         res.end().unwrap();