summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/xhr/resources/inspect-headers.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/xhr/resources/inspect-headers.py
parentInitial commit. (diff)
downloadnode-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/xhr/resources/inspect-headers.py')
-rw-r--r--test/wpt/tests/xhr/resources/inspect-headers.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/wpt/tests/xhr/resources/inspect-headers.py b/test/wpt/tests/xhr/resources/inspect-headers.py
new file mode 100644
index 0000000..123d637
--- /dev/null
+++ b/test/wpt/tests/xhr/resources/inspect-headers.py
@@ -0,0 +1,36 @@
+from wptserve.utils import isomorphic_encode
+
+def get_response(raw_headers, filter_value, filter_name):
+ result = b""
+ # raw_headers.raw_items() returns the (name, value) header pairs as
+ # tuples of strings. Convert them to bytes before comparing.
+ # TODO: Get access to the raw headers, so that whitespace between
+ # name, ":" and value can also be checked:
+ # https://github.com/web-platform-tests/wpt/issues/28756
+ for field in raw_headers.raw_items():
+ name = isomorphic_encode(field[0])
+ value = isomorphic_encode(field[1])
+ if filter_value:
+ if value == filter_value:
+ result += name + b","
+ elif name.lower() == filter_name:
+ result += name + b": " + value + b"\n"
+ return result
+
+def main(request, response):
+ headers = []
+ if b"cors" in request.GET:
+ headers.append((b"Access-Control-Allow-Origin", b"*"))
+ headers.append((b"Access-Control-Allow-Credentials", b"true"))
+ headers.append((b"Access-Control-Allow-Methods", b"GET, POST, PUT, FOO"))
+ headers.append((b"Access-Control-Allow-Headers", b"x-test, x-foo"))
+ headers.append((
+ b"Access-Control-Expose-Headers",
+ b"x-request-method, x-request-content-type, x-request-query, x-request-content-length"))
+ headers.append((b"content-type", b"text/plain"))
+
+ filter_value = request.GET.first(b"filter_value", b"")
+ filter_name = request.GET.first(b"filter_name", b"").lower()
+ result = get_response(request.raw_headers, filter_value, filter_name)
+
+ return headers, result