summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.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/client-hints/critical-ch/resources/echo-critical-hint.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/client-hints/critical-ch/resources/echo-critical-hint.py')
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py b/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py
new file mode 100644
index 0000000000..e4e77ad2a9
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py
@@ -0,0 +1,43 @@
+import sys
+
+def main(request, response):
+ """
+ Simple handler that sets a response header based on which client hint
+ request headers were received.
+ """
+
+ response.headers.append(b"Content-Type", b"text/html; charset=UTF-8")
+ response.headers.append(b"Access-Control-Allow-Origin", b"*")
+ response.headers.append(b"Access-Control-Allow-Headers", b"*")
+ response.headers.append(b"Access-Control-Expose-Headers", b"*")
+
+ response.headers.append(b"Accept-CH", b"sec-ch-device-memory,device-memory")
+
+ critical = b"sec-ch-device-memory,device-memory"
+ if(request.GET.first(b"mismatch", None) is not None):
+ critical = b"sec-ch-viewport-width,viewport-width"
+
+ response.headers.append(b"Critical-CH", critical)
+
+ response.headers.append(b"Cache-Control", b"no-store")
+
+ result = "FAIL"
+
+ if b"sec-ch-device-memory" in request.headers and b"device-memory" in request.headers:
+ result = "PASS"
+
+ token = request.GET.first(b"token", None)
+ if(token is not None):
+ with request.server.stash.lock:
+ count = request.server.stash.take(token)
+ if(count == None):
+ count = 1
+ else:
+ count += 1
+ request.server.stash.put(token, count)
+ result = str(count)
+
+ if b"sec-ch-viewport-width" in request.headers and b"viewport-width" in request.headers:
+ result = "MISMATCH"
+
+ response.content = "<script>window.postMessage('{0}', '*')</script>".format(result)