mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Auto merge of #24370 - jdm:cache-crossorigin-test, r=gterzian
Cache crossorigin test This adds a test for #24356 to ensure that we don't regress our cache behaviour. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24370) <!-- Reviewable:end -->
This commit is contained in:
commit
37ab273c82
3 changed files with 51 additions and 0 deletions
|
@ -297,6 +297,7 @@ fn create_cached_response(
|
||||||
cached_headers: &HeaderMap,
|
cached_headers: &HeaderMap,
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
) -> CachedResponse {
|
) -> CachedResponse {
|
||||||
|
debug!("creating a cached response for {:?}", request.url());
|
||||||
let resource_timing = ResourceFetchTiming::new(request.timing_type());
|
let resource_timing = ResourceFetchTiming::new(request.timing_type());
|
||||||
let mut response = Response::new(
|
let mut response = Response::new(
|
||||||
cached_resource.data.metadata.data.final_url.clone(),
|
cached_resource.data.metadata.data.final_url.clone(),
|
||||||
|
@ -305,6 +306,7 @@ fn create_cached_response(
|
||||||
response.headers = cached_headers.clone();
|
response.headers = cached_headers.clone();
|
||||||
response.body = cached_resource.body.clone();
|
response.body = cached_resource.body.clone();
|
||||||
if let ResponseBody::Receiving(_) = *cached_resource.body.lock().unwrap() {
|
if let ResponseBody::Receiving(_) = *cached_resource.body.lock().unwrap() {
|
||||||
|
debug!("existing body is in progress");
|
||||||
let (done_sender, done_receiver) = unbounded();
|
let (done_sender, done_receiver) = unbounded();
|
||||||
*done_chan = Some((done_sender.clone(), done_receiver));
|
*done_chan = Some((done_sender.clone(), done_receiver));
|
||||||
cached_resource
|
cached_resource
|
||||||
|
@ -571,8 +573,10 @@ impl HttpCache {
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
) -> Option<CachedResponse> {
|
) -> Option<CachedResponse> {
|
||||||
// TODO: generate warning headers as appropriate <https://tools.ietf.org/html/rfc7234#section-5.5>
|
// TODO: generate warning headers as appropriate <https://tools.ietf.org/html/rfc7234#section-5.5>
|
||||||
|
debug!("trying to construct cache response for {:?}", request.url());
|
||||||
if request.method != Method::GET {
|
if request.method != Method::GET {
|
||||||
// Only Get requests are cached, avoid a url based match for others.
|
// Only Get requests are cached, avoid a url based match for others.
|
||||||
|
debug!("non-GET method, not caching");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let entry_key = CacheKey::new(&request);
|
let entry_key = CacheKey::new(&request);
|
||||||
|
@ -588,6 +592,7 @@ impl HttpCache {
|
||||||
let original_request_headers = cached_resource.request_headers.lock().unwrap();
|
let original_request_headers = cached_resource.request_headers.lock().unwrap();
|
||||||
if let Some(vary_value) = cached_headers.typed_get::<Vary>() {
|
if let Some(vary_value) = cached_headers.typed_get::<Vary>() {
|
||||||
if vary_value.is_any() {
|
if vary_value.is_any() {
|
||||||
|
debug!("vary value is any, not caching");
|
||||||
can_be_constructed = false
|
can_be_constructed = false
|
||||||
} else {
|
} else {
|
||||||
// For every header name found in the Vary header of the stored response.
|
// For every header name found in the Vary header of the stored response.
|
||||||
|
@ -602,6 +607,7 @@ impl HttpCache {
|
||||||
// Check that the value of the nominated header field,
|
// Check that the value of the nominated header field,
|
||||||
// in the original request, matches the value in the current request.
|
// in the original request, matches the value in the current request.
|
||||||
if original_header_data != header_data {
|
if original_header_data != header_data {
|
||||||
|
debug!("headers don't match, not caching");
|
||||||
can_be_constructed = false;
|
can_be_constructed = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -613,6 +619,9 @@ impl HttpCache {
|
||||||
// were also absent in the original request.
|
// were also absent in the original request.
|
||||||
can_be_constructed =
|
can_be_constructed =
|
||||||
original_request_headers.get(vary_val).is_none();
|
original_request_headers.get(vary_val).is_none();
|
||||||
|
if !can_be_constructed {
|
||||||
|
debug!("vary header present, not caching");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if !can_be_constructed {
|
if !can_be_constructed {
|
||||||
|
@ -663,6 +672,7 @@ impl HttpCache {
|
||||||
return Some(cached_response);
|
return Some(cached_response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
debug!("couldn't find an appropriate response, not caching");
|
||||||
// The cache wasn't able to construct anything.
|
// The cache wasn't able to construct anything.
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -11353,6 +11353,12 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"mozilla/cache_crossorigin_response.sub.html": [
|
||||||
|
[
|
||||||
|
"mozilla/cache_crossorigin_response.sub.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"mozilla/calc.html": [
|
"mozilla/calc.html": [
|
||||||
[
|
[
|
||||||
"mozilla/calc.html",
|
"mozilla/calc.html",
|
||||||
|
@ -18479,6 +18485,10 @@
|
||||||
"13a1a0fdc15ac05458ebf2c1fd75d501a6de92e3",
|
"13a1a0fdc15ac05458ebf2c1fd75d501a6de92e3",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
|
"mozilla/cache_crossorigin_response.sub.html": [
|
||||||
|
"266995f30afa3e9b3472e4cc43be6493c562aef6",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
"mozilla/calc.html": [
|
"mozilla/calc.html": [
|
||||||
"80aa06e2ae7cd5db585873f147a21382b279b86e",
|
"80aa06e2ae7cd5db585873f147a21382b279b86e",
|
||||||
"testharness"
|
"testharness"
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script>
|
||||||
|
let t = async_test("Cached cross-origin response doesn't hang");
|
||||||
|
|
||||||
|
onload = t.step_func(function() {
|
||||||
|
let complete = 0;
|
||||||
|
function check() {
|
||||||
|
complete++;
|
||||||
|
if (complete == 2) {
|
||||||
|
t.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = "http://{{hosts[][www]]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/is-script-goal.js?pipe=trickle(d5)|header(Cache-Control,max-age=3600)|header(Pragma,)|header(Expires,36000)";
|
||||||
|
|
||||||
|
function loadScript() {
|
||||||
|
let script = document.createElement('script');
|
||||||
|
document.body.appendChild(script);
|
||||||
|
script.src = url;
|
||||||
|
script.onerror = t.unreached_func();
|
||||||
|
script.onload = t.step_func(check);
|
||||||
|
}
|
||||||
|
// Kick off a load so there's a cache entry with an in progress response.
|
||||||
|
loadScript();
|
||||||
|
|
||||||
|
// Kick off a second load after a slight delay which should end up waiting until
|
||||||
|
// the first load is complete before sharing the existing cached response.
|
||||||
|
t.step_timeout(loadScript, 0);
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue