diff --git a/CHANGES.md b/CHANGES.md index 372f4350a..afa86b7a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## 0.6.9 (2018-05-22) -* Drop connection if request's payload is not fulle consumed #236 +* Drop connection if request's payload is not fully consumed #236 + +* Fix streaming response with body compression ## 0.6.8 (2018-05-20) diff --git a/src/fs.rs b/src/fs.rs index c01f97b92..779b419a4 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -20,7 +20,7 @@ use mime_guess::{get_mime_type, guess_mime_type}; use error::Error; use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler}; use header; -use http::{HttpRange, Method, StatusCode}; +use http::{HttpRange, Method, StatusCode, ContentEncoding}; use httpmessage::HttpMessage; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -300,6 +300,7 @@ impl Responder for NamedFile { if let Ok(rangesvec) = HttpRange::parse(rangesheader, length) { length = rangesvec[0].length; offset = rangesvec[0].start; + resp.content_encoding(ContentEncoding::Identity); resp.header( header::CONTENT_RANGE, format!( @@ -898,6 +899,7 @@ mod tests { let request = srv .get() .uri(srv.url("/t%65st/tests/test.binary")) + .no_default_headers() .finish() .unwrap(); @@ -911,6 +913,23 @@ mod tests { .unwrap(); assert_eq!(contentlength, "100"); + + // chunked + let request = srv + .get() + .uri(srv.url("/t%65st/tests/test.binary")) + .finish() + .unwrap(); + + let response = srv.execute(request.send()).unwrap(); + + let te = response + .headers() + .get(header::TRANSFER_ENCODING) + .unwrap() + .to_str() + .unwrap(); + assert_eq!(te, "chunked"); } #[test] diff --git a/src/server/encoding.rs b/src/server/encoding.rs index ea47bf71a..34c589fc8 100644 --- a/src/server/encoding.rs +++ b/src/server/encoding.rs @@ -505,6 +505,11 @@ impl ContentEncoder { } TransferEncoding::eof(buf) } else { + if !(encoding == ContentEncoding::Identity + || encoding == ContentEncoding::Auto) + { + resp.headers_mut().remove(CONTENT_LENGTH); + } ContentEncoder::streaming_encoding(buf, version, resp) } }