summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/range/resources/video-with-range.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/fetch/range/resources/video-with-range.py
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fetch/range/resources/video-with-range.py')
-rw-r--r--testing/web-platform/tests/fetch/range/resources/video-with-range.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/range/resources/video-with-range.py b/testing/web-platform/tests/fetch/range/resources/video-with-range.py
new file mode 100644
index 0000000000..2d15ccf3c4
--- /dev/null
+++ b/testing/web-platform/tests/fetch/range/resources/video-with-range.py
@@ -0,0 +1,43 @@
+import re
+import os
+import json
+from wptserve.utils import isomorphic_decode
+
+def main(request, response):
+ path = os.path.join(request.doc_root, u"media", "sine440.mp3")
+ total_size = os.path.getsize(path)
+ rewrites = json.loads(request.GET.first(b'rewrites', '[]'))
+ range_header = request.headers.get(b'Range')
+ range_header_match = range_header and re.search(r'^bytes=(\d*)-(\d*)$', isomorphic_decode(range_header))
+ start = None
+ end = None
+ if range_header_match:
+ response.status = 206
+ start, end = range_header_match.groups()
+ if range_header:
+ status = 206
+ else:
+ status = 200
+ for rewrite in rewrites:
+ req_start, req_end = rewrite['request']
+ if start == req_start or req_start == '*':
+ if end == req_end or req_end == '*':
+ if 'response' in rewrite:
+ start, end = rewrite['response']
+ if 'status' in rewrite:
+ status = rewrite['status']
+
+ start = int(start or 0)
+ end = int(end or total_size)
+ headers = []
+ if status == 206:
+ headers.append((b"Content-Range", b"bytes %d-%d/%d" % (start, end - 1, total_size)))
+ headers.append((b"Accept-Ranges", b"bytes"))
+
+ headers.append((b"Content-Type", b"audio/mp3"))
+ headers.append((b"Content-Length", str(end - start)))
+ headers.append((b"Cache-Control", b"no-cache"))
+ video_file = open(path, "rb")
+ video_file.seek(start)
+ content = video_file.read(end)
+ return status, headers, content