Skip to content

Commit

Permalink
add pref to disable http cache, mozilla tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Nov 19, 2017
1 parent 5f8a310 commit 6196a6e
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/net/http_cache.rs
Expand Up @@ -18,6 +18,7 @@ use hyper_serde::Serde;
use net_traits::{Metadata, FetchMetadata};
use net_traits::request::Request;
use net_traits::response::{HttpsState, Response, ResponseBody};
use servo_config::prefs::PREFS;
use servo_url::ServoUrl;
use std::collections::HashMap;
use std::str;
Expand Down Expand Up @@ -609,6 +610,9 @@ impl HttpCache {
/// Storing Responses in Caches.
/// <https://tools.ietf.org/html/rfc7234#section-3>
pub fn store(&mut self, request: &Request, response: &Response) {
if PREFS.get("network.http-cache.disabled").as_boolean().unwrap_or(false) {
return
}
if request.method != Method::Get {
// Only Get requests are cached.
return
Expand Down
1 change: 1 addition & 0 deletions resources/prefs.json
Expand Up @@ -66,6 +66,7 @@
"layout.text-orientation.enabled": false,
"layout.viewport.enabled": false,
"layout.writing-mode.enabled": false,
"network.http-cache.disabled": false,
"network.mime.sniff": false,
"session-history.max-length": 20,
"shell.builtin-key-shortcuts.enabled": true,
Expand Down
19 changes: 19 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -12466,6 +12466,11 @@
{}
]
],
"mozilla/resources/http-cache.js": [
[
{}
]
],
"mozilla/resources/iframe_contentDocument_inner.html": [
[
{}
Expand Down Expand Up @@ -33212,6 +33217,12 @@
{}
]
],
"mozilla/http-cache.html": [
[
"/_mozilla/mozilla/http-cache.html",
{}
]
],
"mozilla/iframe-unblock-onload.html": [
[
"/_mozilla/mozilla/iframe-unblock-onload.html",
Expand Down Expand Up @@ -66299,6 +66310,10 @@
"592f69ee432ba5bc7a2f2649e72e083d21393496",
"testharness"
],
"mozilla/http-cache.html": [
"33827dc9bdb0efcbcae4f730086693be315cfc14",
"testharness"
],
"mozilla/iframe-unblock-onload.html": [
"8734756947d36b047df256f27adc56fce7e31f88",
"testharness"
Expand Down Expand Up @@ -71971,6 +71986,10 @@
"78686147f85e4146e7fc58c1f67a613f65b099a2",
"support"
],
"mozilla/resources/http-cache.js": [
"c6b1ee9def26d4e12a1b93e551c225f82b4717c2",
"support"
],
"mozilla/resources/iframe_contentDocument_inner.html": [
"eb1b1ae3bb7a437fc4fbdd1f537881890fe6347c",
"support"
Expand Down
3 changes: 3 additions & 0 deletions tests/wpt/mozilla/meta/mozilla/http-cache.html.ini
@@ -0,0 +1,3 @@
[http-cache.html]
type: testharness
prefs: [network.http-cache.disabled:true]
50 changes: 50 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/http-cache.html
@@ -0,0 +1,50 @@
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/http-cache.js"></script>
<script src="/fetch/http-cache/resources/http-cache.py"></script>
<script>
var tests = [];
function check_status(status) {
var code = status[0];
var phrase = status[1];
var body = status[2];
if (body === undefined) {
body = http_content(code);
}
tests.push({
name: 'HTTP cache, when disabled, does not cache a ' + code + ' response.',
requests: [
{
template: "fresh",
response_status: [code, phrase],
response_body: body
}, {
expected_type: "not_cached",
response_status: [code, phrase],
response_body: body
}
]
})
}
[
[200, 'OK'],
[203, "Non-Authoritative Information"],
[204, "No Content", ""],
[299, "Whatever"],
[400, "Bad Request"],
[404, "Not Found"],
[410, "Gone"],
[499, "Whatever"],
[500, "Internal Server Error"],
[502, "Bad Gateway"],
[503, "Service Unavailable"],
[504, "Gateway Timeout"],
[599, "Whatever"]
].forEach(check_status);
run_tests(tests);
</script>
</head>
</html>

0 comments on commit 6196a6e

Please sign in to comment.