commit cf03438176fb29d12403147de7676a951a8fe4da
parent 11d5e07b847a6a81f6a4861f53a1a15a4825d8f5
Author: rayguo17 <rayguo17@gmail.com>
Date: Mon, 27 Oct 2025 10:07:35 +0000
Bug 1995975 [wpt PR 55613] - fix http cache reconstruct response from cache after validation behaviour, a=testonly
Automatic update from web-platform-tests
fix http cache reconstruct response from cache after validation behaviour
Signed-off-by: rayguo17 <rayguo17@gmail.com>
--
fixing test for UA that will not construct partial response from expired cache
Signed-off-by: rayguo17 <rayguo17@gmail.com>
--
wpt-commits: 32bdd0376eaca35ac3a04f4bba512472f02b5891, 51b633d5898e864d21d761c72d9a5903efbe9af8
wpt-pr: 55613
Diffstat:
2 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/fetch/range/cache-revalidate-construct-range-response.html b/testing/web-platform/tests/fetch/range/cache-revalidate-construct-range-response.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+
+promise_test(async t => {
+ const url = new URL('resources/video-with-aged-proxy-cache.py', location.href);
+ const response_1 = await fetch(url.toString());
+ assert_equals(response_1.status, 200, 'Initial fetch should succeed with 200');
+ const response_1_blob = await response_1.blob();
+ assert_equals(response_1_blob.size, 80666, 'Initial fetch should get full content');
+ const response_2 = await fetch(url.toString(), {
+ headers: {'Range': 'bytes=0-99'}
+ });
+ const response_2_blob = await response_2.blob();
+ assert_equals(response_2.status, 206, 'Range fetch after cache revalidation should succeed with 206');
+ assert_equals(response_2_blob.size, 100, 'Range fetch after cache revalidation should get partial content');
+}, `Range request after cache revalidation with 200 OK response should succeed`);
+
+</script>
+</body>
+\ No newline at end of file
diff --git a/testing/web-platform/tests/fetch/range/resources/video-with-aged-proxy-cache.py b/testing/web-platform/tests/fetch/range/resources/video-with-aged-proxy-cache.py
@@ -0,0 +1,64 @@
+import re
+import os
+import json
+from wptserve.utils import isomorphic_decode
+
+ENTITY_TAG = b'"sine440-v1"'
+# There should be two requests made to this resource:
+# 1. A request fetch the whole video. This request should receive a
+# 200 Success response with a aged header of value more
+# than 24 hours in the past, simulating an aged proxy cache.
+# 2.a A subsequent request with a Range header to revalidate the cached content.
+# This request should include an If-Modified-Since / If-Not-Match header
+# and should response with a 304 Not Modified response.
+# 2.b A subsequent request with a Range header to fetch a range of the video.
+# But without Http-Cache revalidation related header.
+# This request should receive a 206 Partial Content response with the
+# requested range of the video.
+
+def main(request, response):
+ path = os.path.join(request.doc_root, u"media", "sine440.mp3")
+ total_size = os.path.getsize(path)
+ if_modified_since = request.headers.get(b'If-Modified-Since')
+ if_none_match = request.headers.get(b'If-Not-Match')
+ range_header = request.headers.get(b'Range')
+ range_header_match = range_header and re.search(r'^bytes=(\d*)-(\d*)$', isomorphic_decode(range_header))
+
+ if range_header_match:
+ start, end = range_header_match.groups()
+ start = int(start or 0)
+ end = int(end or total_size)
+ status = 206
+ elif if_modified_since or if_none_match:
+ status = 304
+ start = 0
+ end = 0
+ else:
+ status = 200
+ start = 0
+ end = total_size
+
+ response.status = status
+ headers = []
+ if status == 200:
+ headers.append((b"Age", b"86400"))
+ headers.append((b"Expires", b"Wed, 21 Oct 2015 07:28:00 GMT"))
+ headers.append((b"Last-Modified", b"Wed, 21 Oct 2015 07:28:00 GMT"))
+ headers.append((b"ETag", ENTITY_TAG))
+ video_file = open(path, "rb")
+ video_file.seek(start)
+ content = video_file.read(end)
+ elif status == 206:
+ headers.append((b"Content-Range", b"bytes %d-%d/%d" % (start, end, total_size)))
+ headers.append((b"Accept-Ranges", b"bytes"))
+ headers.append((b"ETag", ENTITY_TAG))
+ video_file = open(path, "rb")
+ video_file.seek(start)
+ end = min(end+1, total_size)
+ content = video_file.read(end-start)
+ else:
+ content = b""
+ headers.append((b"Content-Length", str(end - start)))
+ headers.append((b"Content-Type", b"audio/mp3"))
+
+ return status, headers, content