mirror of
https://github.com/servo/servo.git
synced 2025-07-16 03:43:38 +01:00
Accept Brotli-compressed HTTP responses #8156
This commit is contained in:
parent
959ae86bd0
commit
468eaac096
11 changed files with 97 additions and 9 deletions
|
@ -16,6 +16,9 @@ path = "../util"
|
|||
[dependencies.devtools_traits]
|
||||
path = "../devtools_traits"
|
||||
|
||||
[dependencies.brotli]
|
||||
git = "https://github.com/ende76/brotli-rs"
|
||||
|
||||
[dependencies.plugins]
|
||||
path = "../plugins"
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
use brotli::Decompressor;
|
||||
use cookie;
|
||||
use cookie_storage::CookieStorage;
|
||||
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest};
|
||||
|
@ -154,10 +155,9 @@ pub trait HttpResponse: Read {
|
|||
Some(Encoding::Gzip)
|
||||
} else if encodings.contains(&Encoding::Deflate) {
|
||||
Some(Encoding::Deflate)
|
||||
} else {
|
||||
// TODO: Is this the correct behaviour?
|
||||
None
|
||||
}
|
||||
} else if encodings.contains(&Encoding::EncodingExt("br".to_owned())) {
|
||||
Some(Encoding::EncodingExt("br".to_owned()))
|
||||
} else { None }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -302,7 +302,8 @@ fn set_default_accept_encoding(headers: &mut Headers) {
|
|||
|
||||
headers.set(AcceptEncoding(vec![
|
||||
qitem(Encoding::Gzip),
|
||||
qitem(Encoding::Deflate)
|
||||
qitem(Encoding::Deflate),
|
||||
qitem(Encoding::EncodingExt("br".to_owned()))
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -394,6 +395,7 @@ impl<R: HttpResponse> Read for StreamedResponse<R> {
|
|||
match self.decoder {
|
||||
Decoder::Gzip(ref mut d) => d.read(buf),
|
||||
Decoder::Deflate(ref mut d) => d.read(buf),
|
||||
Decoder::Brotli(ref mut d) => d.read(buf),
|
||||
Decoder::Plain(ref mut d) => d.read(buf)
|
||||
}
|
||||
}
|
||||
|
@ -421,6 +423,10 @@ impl<R: HttpResponse> StreamedResponse<R> {
|
|||
let response_decoding = DeflateDecoder::new(response);
|
||||
Ok(StreamedResponse::new(m, Decoder::Deflate(response_decoding)))
|
||||
}
|
||||
Some(Encoding::EncodingExt(ref ext)) if ext == "br" => {
|
||||
let response_decoding = Decompressor::new(response);
|
||||
Ok(StreamedResponse::new(m, Decoder::Brotli(response_decoding)))
|
||||
}
|
||||
_ => {
|
||||
Ok(StreamedResponse::new(m, Decoder::Plain(response)))
|
||||
}
|
||||
|
@ -431,6 +437,7 @@ impl<R: HttpResponse> StreamedResponse<R> {
|
|||
enum Decoder<R: Read> {
|
||||
Gzip(GzDecoder<R>),
|
||||
Deflate(DeflateDecoder<R>),
|
||||
Brotli(Decompressor<R>),
|
||||
Plain(R)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ extern crate cookie as cookie_rs;
|
|||
extern crate devtools_traits;
|
||||
extern crate euclid;
|
||||
extern crate flate2;
|
||||
extern crate brotli;
|
||||
extern crate hyper;
|
||||
extern crate ipc_channel;
|
||||
extern crate net_traits;
|
||||
|
|
6
components/servo/Cargo.lock
generated
6
components/servo/Cargo.lock
generated
|
@ -138,6 +138,11 @@ dependencies = [
|
|||
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli"
|
||||
version = "0.3.17"
|
||||
source = "git+https://github.com/ende76/brotli-rs#4a8c42cce771ded65fe64d6816f5d7303006b2ea"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.3.13"
|
||||
|
@ -1200,6 +1205,7 @@ dependencies = [
|
|||
name = "net"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"brotli 0.3.17 (git+https://github.com/ende76/brotli-rs)",
|
||||
"cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"devtools_traits 0.0.1",
|
||||
"euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue