From 9c205f9f1df451a5a6039f5105307117223f57d4 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 4 Apr 2019 14:00:56 -0700 Subject: [PATCH] update tests for content-encoding --- actix-files/src/lib.rs | 20 +++++++++++++++++++- actix-files/src/named.rs | 7 +++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 8404ab319..e2fa06e12 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -979,14 +979,32 @@ mod tests { .to_request(); let res = test::call_success(&mut srv, request); assert_eq!(res.status(), StatusCode::OK); + assert!(!res.headers().contains_key(header::CONTENT_ENCODING)); + } + #[test] + fn test_named_file_content_encoding_gzip() { + let mut srv = test::init_service(App::new().enable_encoding().service( + web::resource("/").to(|| { + NamedFile::open("Cargo.toml") + .unwrap() + .set_content_encoding(header::ContentEncoding::Gzip) + }), + )); + + let request = TestRequest::get() + .uri("/") + .header(header::ACCEPT_ENCODING, "gzip") + .to_request(); + let res = test::call_success(&mut srv, request); + assert_eq!(res.status(), StatusCode::OK); assert_eq!( res.headers() .get(header::CONTENT_ENCODING) .unwrap() .to_str() .unwrap(), - "identity" + "gzip" ); } diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 4ee1a3caa..717b058cf 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -296,10 +296,9 @@ impl Responder for NamedFile { header::CONTENT_DISPOSITION, self.content_disposition.to_string(), ); - // TODO blocking by compressing - // if let Some(current_encoding) = self.encoding { - // resp.content_encoding(current_encoding); - // } + if let Some(current_encoding) = self.encoding { + resp.encoding(current_encoding); + } let reader = ChunkedReadFile { size: self.md.len(), offset: 0,