Files
sousa-gecko/testing/web-platform/tests/tools/websocket/h3/headers.py
T
Mayur 8285f75dbd Bug 2046740 [wpt PR 60554] - Add WebSocket/H3 handshake helpers for WPT, a=testonly
Automatic update from web-platform-tests
Add WebSocket/H3 handshake helpers for WPT (#60554)

* Add WebSocket/H3 handshake helpers for WPT

* Add WebSocket/H3 handshake helpers for WPT

---------

Co-authored-by: Mayur Patil <patilmayur@microsoft.com>
--

wpt-commits: edb7f2309faf3a5dda5f147cb6d9198e253c828e
wpt-pr: 60554
2026-07-10 09:20:51 +00:00

36 lines
1.1 KiB
Python

# mypy: allow-untyped-defs
from collections import OrderedDict
from typing import Dict
from wptserve.utils import isomorphic_decode
class H3Headers(Dict[str, str]):
"""Header store that adapts HTTP/3 headers to pywebsocket3 expectations."""
_H3_PSEUDO_HEADERS = {
'method', 'scheme', 'host', 'path', 'authority', 'status', 'protocol'
}
def __init__(self, headers):
super().__init__()
self.raw_headers = OrderedDict()
for key, value in headers:
key = isomorphic_decode(key)
value = isomorphic_decode(value)
self.raw_headers[key] = value
dict.__setitem__(self, key, value)
dict.__setitem__(self, self._normalize_key(key), value)
@staticmethod
def _normalize_key(key: str) -> str:
if key.startswith(':') and key[1:] in H3Headers._H3_PSEUDO_HEADERS:
return key[1:]
return key
# TODO This does not seem relevant for H3 headers, so using a dummy function for now
def getallmatchingheaders(self, _header):
return ['dummy function']