From 7565ed8e06c9dbc6679be51c48a24eed3a1f8490 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 8 Nov 2017 19:42:13 -0800 Subject: [PATCH] use higher pripority for br --- README.md | 2 +- src/encoding.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 533049e6b..4d9795c97 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Actix web is licensed under the [Apache-2.0 license](http://opensource.org/licen * Streaming and pipelining * Keep-alive and slow requests handling * [WebSockets](https://actix.github.io/actix-web/actix_web/ws/index.html) - * Transparent content compression/decompression + * Transparent content compression/decompression (br, gzip, deflate) * Configurable request routing * Multipart streams * Middlewares diff --git a/src/encoding.rs b/src/encoding.rs index 2d6d95b10..f0fdb6bc3 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -42,6 +42,15 @@ impl ContentEncoding { ContentEncoding::Identity | ContentEncoding::Auto => "identity", } } + // default quality + fn quality(&self) -> f64 { + match *self { + ContentEncoding::Br => 1.1, + ContentEncoding::Gzip => 1.0, + ContentEncoding::Deflate => 0.9, + ContentEncoding::Identity | ContentEncoding::Auto => 0.1, + } + } } impl<'a> From<&'a str> for ContentEncoding { @@ -464,7 +473,7 @@ impl PayloadEncoder { ContentEncoding::Gzip => ContentEncoder::Gzip( GzEncoder::new(transfer, Compression::Default)), ContentEncoding::Br => ContentEncoder::Br( - BrotliEncoder::new(transfer, 6)), + BrotliEncoder::new(transfer, 5)), ContentEncoding::Identity => ContentEncoder::Identity(transfer), ContentEncoding::Auto => unreachable!() @@ -786,7 +795,7 @@ impl AcceptEncoding { _ => ContentEncoding::from(parts[0]), }; let quality = match parts.len() { - 1 => 1.0, + 1 => encoding.quality(), _ => match f64::from_str(parts[1]) { Ok(q) => q, Err(_) => 0.0,