summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py')
-rw-r--r--testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py b/testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py
new file mode 100644
index 0000000000..62631d922f
--- /dev/null
+++ b/testing/web-platform/tests/speculation-rules/prerender/resources/deprecated-broadcast-channel.py
@@ -0,0 +1,28 @@
+import json
+import time
+def main(request, response):
+ uid = request.GET.first(b"uid")
+ name = request.GET.first(b"name")
+ time.sleep(0.1)
+
+ messagesByName = []
+ if request.method == 'POST':
+ with request.server.stash.lock:
+ messages = request.server.stash.take(uid) or {}
+ if name in messages:
+ messagesByName = messages[name]
+
+ messagesByName.append(json.loads(request.body))
+ messages[name] = messagesByName
+ request.server.stash.put(uid, messages)
+ response.status = 204
+ else:
+ with request.server.stash.lock:
+ messages = request.server.stash.take(uid) or {}
+ if name in messages:
+ messagesByName = messages[name]
+
+ request.server.stash.put(uid, messages)
+ response.status = 200
+ response.headers['Content-Type'] = 'application/json'
+ response.content = json.dumps(messagesByName)