diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py')
-rw-r--r-- | test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py b/test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py new file mode 100644 index 0000000..ac0850f --- /dev/null +++ b/test/wpt/tests/service-workers/service-worker/resources/update-worker-from-file.py @@ -0,0 +1,33 @@ +import os + +from wptserve.utils import isomorphic_encode + +def serve_js_from_file(request, response, filename): + body = b'' + path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), filename) + with open(path, 'rb') as f: + body = f.read() + return ( + [ + (b'Cache-Control', b'no-cache, must-revalidate'), + (b'Pragma', b'no-cache'), + (b'Content-Type', b'application/javascript') + ], body) + +def main(request, response): + key = request.GET[b"Key"] + + visited_count = request.server.stash.take(key) + if visited_count is None: + visited_count = 0 + + # Keep how many times the test requested this resource. + visited_count += 1 + request.server.stash.put(key, visited_count) + + # Serve a file based on how many times it's requested. + if visited_count == 1: + return serve_js_from_file(request, response, request.GET[b"First"]) + if visited_count == 2: + return serve_js_from_file(request, response, request.GET[b"Second"]) + raise u"Unknown state" |