1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-12-18 01:43:58 +01:00

Fix streaming response with body compression

This commit is contained in:
Nikolay Kim 2018-05-21 20:50:10 -07:00
parent 76d790425f
commit 2159158c30
3 changed files with 28 additions and 2 deletions

View File

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

View File

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

View File

@ -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)
}
}