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
36 lines
1.1 KiB
Python
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']
|