1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

use higher pripority for br

This commit is contained in:
Nikolay Kim 2017-11-08 19:42:13 -08:00
parent 02fb424659
commit 7565ed8e06
2 changed files with 12 additions and 3 deletions

View File

@ -17,7 +17,7 @@ Actix web is licensed under the [Apache-2.0 license](http://opensource.org/licen
* Streaming and pipelining * Streaming and pipelining
* Keep-alive and slow requests handling * Keep-alive and slow requests handling
* [WebSockets](https://actix.github.io/actix-web/actix_web/ws/index.html) * [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 * Configurable request routing
* Multipart streams * Multipart streams
* Middlewares * Middlewares

View File

@ -42,6 +42,15 @@ impl ContentEncoding {
ContentEncoding::Identity | ContentEncoding::Auto => "identity", 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 { impl<'a> From<&'a str> for ContentEncoding {
@ -464,7 +473,7 @@ impl PayloadEncoder {
ContentEncoding::Gzip => ContentEncoder::Gzip( ContentEncoding::Gzip => ContentEncoder::Gzip(
GzEncoder::new(transfer, Compression::Default)), GzEncoder::new(transfer, Compression::Default)),
ContentEncoding::Br => ContentEncoder::Br( ContentEncoding::Br => ContentEncoder::Br(
BrotliEncoder::new(transfer, 6)), BrotliEncoder::new(transfer, 5)),
ContentEncoding::Identity => ContentEncoder::Identity(transfer), ContentEncoding::Identity => ContentEncoder::Identity(transfer),
ContentEncoding::Auto => ContentEncoding::Auto =>
unreachable!() unreachable!()
@ -786,7 +795,7 @@ impl AcceptEncoding {
_ => ContentEncoding::from(parts[0]), _ => ContentEncoding::from(parts[0]),
}; };
let quality = match parts.len() { let quality = match parts.len() {
1 => 1.0, 1 => encoding.quality(),
_ => match f64::from_str(parts[1]) { _ => match f64::from_str(parts[1]) {
Ok(q) => q, Ok(q) => q,
Err(_) => 0.0, Err(_) => 0.0,