diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 2e92fcaa1..52327d6e7 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -894,9 +894,16 @@ mod tests { let resp = HttpResponse::build(StatusCode::OK).finish().unwrap(); assert_eq!(resp.content_encoding(), None); + #[cfg(feature="brotli")] + { + let resp = HttpResponse::build(StatusCode::OK) + .content_encoding(ContentEncoding::Br).finish().unwrap(); + assert_eq!(resp.content_encoding(), Some(ContentEncoding::Br)); + } + let resp = HttpResponse::build(StatusCode::OK) - .content_encoding(ContentEncoding::Br).finish().unwrap(); - assert_eq!(resp.content_encoding(), Some(ContentEncoding::Br)); + .content_encoding(ContentEncoding::Gzip).finish().unwrap(); + assert_eq!(resp.content_encoding(), Some(ContentEncoding::Gzip)); } #[test] diff --git a/src/server/encoding.rs b/src/server/encoding.rs index bd6921d21..5374b6244 100644 --- a/src/server/encoding.rs +++ b/src/server/encoding.rs @@ -418,12 +418,12 @@ impl ContentEncoder { let transfer = TransferEncoding::eof(tmp.clone()); let mut enc = match encoding { ContentEncoding::Deflate => ContentEncoder::Deflate( - DeflateEncoder::new(transfer, Compression::default())), + DeflateEncoder::new(transfer, Compression::fast())), ContentEncoding::Gzip => ContentEncoder::Gzip( - GzEncoder::new(transfer, Compression::default())), + GzEncoder::new(transfer, Compression::fasr())), #[cfg(feature="brotli")] ContentEncoding::Br => ContentEncoder::Br( - BrotliEncoder::new(transfer, 5)), + BrotliEncoder::new(transfer, 3)), ContentEncoding::Identity => ContentEncoder::Identity(transfer), ContentEncoding::Auto => unreachable!() }; diff --git a/tests/test_client.rs b/tests/test_client.rs index f8a9cdffc..6452baef4 100644 --- a/tests/test_client.rs +++ b/tests/test_client.rs @@ -188,6 +188,7 @@ fn test_client_gzip_encoding_large_random() { assert_eq!(bytes, Bytes::from(data)); } +#[cfg(feature="brotli")] #[test] fn test_client_brotli_encoding() { let mut srv = test::TestServer::new(|app| app.handler(|req: HttpRequest| { @@ -212,6 +213,7 @@ fn test_client_brotli_encoding() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(feature="brotli")] #[test] fn test_client_brotli_encoding_large_random() { let data = rand::thread_rng() @@ -242,6 +244,7 @@ fn test_client_brotli_encoding_large_random() { assert_eq!(bytes, Bytes::from(data)); } +#[cfg(feature="brotli")] #[test] fn test_client_deflate_encoding() { let mut srv = test::TestServer::new(|app| app.handler(|req: HttpRequest| { @@ -266,6 +269,7 @@ fn test_client_deflate_encoding() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(feature="brotli")] #[test] fn test_client_deflate_encoding_large_random() { let data = rand::thread_rng() diff --git a/tests/test_server.rs b/tests/test_server.rs index 9cc09d029..d6c25f737 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -6,9 +6,11 @@ extern crate h2; extern crate http; extern crate bytes; extern crate flate2; -extern crate brotli2; extern crate rand; +#[cfg(feature="brotli")] +extern crate brotli2; + use std::{net, thread, time}; use std::io::{Read, Write}; use std::sync::{Arc, mpsc}; @@ -16,6 +18,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use flate2::Compression; use flate2::read::GzDecoder; use flate2::write::{GzEncoder, DeflateEncoder, DeflateDecoder}; +#[cfg(feature="brotli")] use brotli2::write::{BrotliEncoder, BrotliDecoder}; use futures::{Future, Stream}; use futures::stream::once; @@ -291,6 +294,7 @@ fn test_body_chunked_implicit() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(feature="brotli")] #[test] fn test_body_br_streaming() { let mut srv = test::TestServer::new( @@ -443,6 +447,7 @@ fn test_body_deflate() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(feature="brotli")] #[test] fn test_body_brotli() { let mut srv = test::TestServer::new( @@ -649,6 +654,7 @@ fn test_reading_deflate_encoding_large_random() { assert_eq!(bytes, Bytes::from(data)); } +#[cfg(feature="brotli")] #[test] fn test_brotli_encoding() { let mut srv = test::TestServer::new(|app| app.handler(|req: HttpRequest| { @@ -677,6 +683,7 @@ fn test_brotli_encoding() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(feature="brotli")] #[test] fn test_brotli_encoding_large() { let data = STR.repeat(10);