mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 05:08:36 +02:00
MozReview-Commit-ID: FIohq85kl1G --HG-- rename : testing/web-platform/tests/XMLHttpRequest/event-upload-progress-crossorigin.sub.htm => testing/web-platform/tests/XMLHttpRequest/event-upload-progress-crossorigin.htm rename : testing/web-platform/tests/XMLHttpRequest/send-non-same-origin.sub.htm => testing/web-platform/tests/XMLHttpRequest/send-non-same-origin.htm rename : testing/web-platform/tests/html/browsers/history/the-location-interface/security_location_0.sub.htm => testing/web-platform/tests/html/browsers/history/the-location-interface/security_location_0.htm rename : testing/web-platform/tests/html/browsers/the-window-object/security-window/window-security.sub.html => testing/web-platform/tests/html/browsers/the-window-object/security-window/window-security.html rename : testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/frameElement.sub.html => testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/frameElement.html rename : testing/web-platform/tests/html/browsers/windows/targeting-cross-origin-nested-browsing-contexts.sub.html => testing/web-platform/tests/html/browsers/windows/targeting-cross-origin-nested-browsing-contexts.html rename : testing/web-platform/tests/html/dom/documents/dom-tree-accessors/Document.currentScript.sub.html => testing/web-platform/tests/html/dom/documents/dom-tree-accessors/Document.currentScript.html rename : testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_href_specified.sub.html => testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_href_specified.html
51 lines
1.8 KiB
HTML
51 lines
1.8 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Request ETag</title>
|
|
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/utils.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
promise_test(function() {
|
|
var cacheBuster = token(); // ensures first request is uncached
|
|
var url = "../resources/cache.py?v=" + cacheBuster;
|
|
var etag;
|
|
|
|
// make the first request
|
|
return fetch(url).then(function(response) {
|
|
// ensure we're getting the regular, uncached response
|
|
assert_equals(response.status, 200);
|
|
assert_equals(response.headers.get("X-HTTP-STATUS"), null)
|
|
|
|
return response.text(); // consuming the body, just to be safe
|
|
}).then(function(body) {
|
|
// make a second request
|
|
return fetch(url);
|
|
}).then(function(response) {
|
|
// while the server responds with 304 if our browser sent the correct
|
|
// If-None-Match request header, at the JavaScript level this surfaces
|
|
// as 200
|
|
assert_equals(response.status, 200);
|
|
assert_equals(response.headers.get("X-HTTP-STATUS"), "304")
|
|
|
|
etag = response.headers.get("ETag")
|
|
|
|
return response.text(); // consuming the body, just to be safe
|
|
}).then(function(body) {
|
|
// make a third request, explicitly setting If-None-Match request header
|
|
var headers = { "If-None-Match": etag }
|
|
return fetch(url, { headers: headers })
|
|
}).then(function(response) {
|
|
// 304 now surfaces thanks to the explicit If-None-Match request header
|
|
assert_equals(response.status, 304);
|
|
});
|
|
}, "Testing conditional GET with ETags");
|
|
|
|
done();
|
|
</script>
|
|
</body>
|
|
</html>
|