From 185e710dc87d407d57004c199c9a7552dde38af8 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 6 Jul 2018 08:24:36 +0600 Subject: [PATCH] do not drop content-encoding header in case of identity #363 --- src/server/h1writer.rs | 5 ++++- tests/test_server.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/server/h1writer.rs b/src/server/h1writer.rs index d8ef41517..724ee3c65 100644 --- a/src/server/h1writer.rs +++ b/src/server/h1writer.rs @@ -199,7 +199,10 @@ impl Writer for H1Writer { let mut buf = &mut *(buffer.bytes_mut() as *mut [u8]); for (key, value) in msg.headers() { match *key { - TRANSFER_ENCODING | CONTENT_ENCODING => continue, + TRANSFER_ENCODING => continue, + CONTENT_ENCODING => if encoding != ContentEncoding::Identity { + continue; + }, CONTENT_LENGTH => match info.length { ResponseLength::None => (), _ => continue, diff --git a/tests/test_server.rs b/tests/test_server.rs index 4c50434c2..82a318e59 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -470,6 +470,39 @@ fn test_body_chunked_explicit() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[test] +fn test_body_identity() { + let mut e = DeflateEncoder::new(Vec::new(), Compression::default()); + e.write_all(STR.as_ref()).unwrap(); + let enc = e.finish().unwrap(); + let enc2 = enc.clone(); + + let mut srv = test::TestServer::new(move |app| { + let enc3 = enc2.clone(); + app.handler(move |_| { + HttpResponse::Ok() + .content_encoding(http::ContentEncoding::Identity) + .header(http::header::CONTENT_ENCODING, "deflate") + .body(enc3.clone()) + }) + }); + + // client request + let request = srv + .get() + .header("accept-encoding", "deflate") + .finish() + .unwrap(); + let response = srv.execute(request.send()).unwrap(); + assert!(response.status().is_success()); + + // read response + let bytes = srv.execute(response.body()).unwrap(); + + // decode deflate + assert_eq!(bytes, Bytes::from(STR)); +} + #[test] fn test_body_deflate() { let mut srv = test::TestServer::new(|app| {