mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -307,7 +307,9 @@ fn test_check_default_headers_loaded_in_every_request() {
|
|||
load_data.method = Method::Get;
|
||||
|
||||
let mut headers = Headers::new();
|
||||
headers.set(AcceptEncoding(vec![qitem(Encoding::Gzip), qitem(Encoding::Deflate)]));
|
||||
headers.set(AcceptEncoding(vec![qitem(Encoding::Gzip),
|
||||
qitem(Encoding::Deflate),
|
||||
qitem(Encoding::EncodingExt("br".to_owned()))]));
|
||||
headers.set(Host { hostname: "mozilla.com".to_owned() , port: None });
|
||||
let accept = Accept(vec![
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
|
||||
|
@ -776,7 +778,9 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
|
|||
#[test]
|
||||
fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
|
||||
let mut accept_encoding_headers = Headers::new();
|
||||
accept_encoding_headers.set(AcceptEncoding(vec![qitem(Encoding::Gzip), qitem(Encoding::Deflate)]));
|
||||
accept_encoding_headers.set(AcceptEncoding(vec![qitem(Encoding::Gzip),
|
||||
qitem(Encoding::Deflate),
|
||||
qitem(Encoding::EncodingExt("br".to_owned()))]));
|
||||
|
||||
let url = Url::parse("http://mozilla.com").unwrap();
|
||||
let mut load_data = LoadData::new(url.clone(), None);
|
||||
|
|
|
@ -35349,4 +35349,4 @@
|
|||
"rev": "7123012427f92f0dc38a120e6e86a75b6c03aab5",
|
||||
"url_base": "/",
|
||||
"version": 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4567,6 +4567,12 @@
|
|||
"url": "/_mozilla/mozilla/proxy_setter.html"
|
||||
}
|
||||
],
|
||||
"mozilla/response-data-brotli.htm": [
|
||||
{
|
||||
"path": "mozilla/response-data-brotli.htm",
|
||||
"url": "/_mozilla/mozilla/response-data-brotli.htm"
|
||||
}
|
||||
],
|
||||
"mozilla/script_type.html": [
|
||||
{
|
||||
"path": "mozilla/script_type.html",
|
||||
|
@ -8730,4 +8736,4 @@
|
|||
"rev": null,
|
||||
"url_base": "/_mozilla/",
|
||||
"version": 2
|
||||
}
|
||||
}
|
7
tests/wpt/mozilla/tests/mozilla/resources/brotli.py
Normal file
7
tests/wpt/mozilla/tests/mozilla/resources/brotli.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
def main(request, response):
|
||||
output = '\x1b\x03)\x00\xa4\xcc\xde\xe2\xb3 vA\x00\x0c'
|
||||
headers = [("Content-type", "text/plain"),
|
||||
("Content-Encoding", "br"),
|
||||
("Content-Length", len(output))]
|
||||
|
||||
return headers, output
|
42
tests/wpt/mozilla/tests/mozilla/response-data-brotli.htm
Normal file
42
tests/wpt/mozilla/tests/mozilla/response-data-brotli.htm
Normal file
|
@ -0,0 +1,42 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: Brotli response was correctly inflated</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="following::p[contains(text(),'content-encodings')]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function request(input) {
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
|
||||
client.open("POST", "resources/brotli.py", false);
|
||||
|
||||
client.onreadystatechange = test.step_func(function () {
|
||||
if (client.readyState === 4) {
|
||||
var len = parseInt(client.getResponseHeader('content-length'), 10);
|
||||
|
||||
assert_equals(client.getResponseHeader('content-encoding'), 'br');
|
||||
assert_true(len < input.length);
|
||||
assert_equals(client.responseText, input);
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
|
||||
client.send(input);
|
||||
}, document.title);
|
||||
}
|
||||
|
||||
var wellCompressableData = '';
|
||||
for (var i = 0; i < 500; i++) {
|
||||
wellCompressableData += 'foofoofoofoofoofoofoo';
|
||||
}
|
||||
|
||||
request(wellCompressableData);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue