1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

do not drop content-encoding header in case of identity #363

This commit is contained in:
Nikolay Kim 2018-07-06 08:24:36 +06:00
parent 9070d59ea8
commit 185e710dc8
2 changed files with 37 additions and 1 deletions

View File

@ -199,7 +199,10 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
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,

View File

@ -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| {