mirror of
https://github.com/actix/actix-web.git
synced 2024-11-18 15:41:17 +00:00
disable brotli if feature is not enabled, faster compression
This commit is contained in:
parent
ce6d237cc1
commit
d5fa0a9418
4 changed files with 24 additions and 6 deletions
|
@ -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]
|
||||
|
|
|
@ -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!()
|
||||
};
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue