diff options
Diffstat (limited to 'testing/web-platform/tests/webtransport/handlers')
8 files changed, 188 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webtransport/handlers/abort-stream-from-server.py b/testing/web-platform/tests/webtransport/handlers/abort-stream-from-server.py new file mode 100644 index 0000000000..1d92b705e6 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/abort-stream-from-server.py @@ -0,0 +1,27 @@ +from typing import Optional +from urllib.parse import urlsplit, parse_qsl + + +def session_established(session): + path: Optional[bytes] = None + for key, value in session.request_headers: + if key == b':path': + path = value + assert path is not None + qs = dict(parse_qsl(urlsplit(path).query)) + code = qs[b'code'] + if code is None: + raise Exception('code is missing, path = {}'.format(path)) + session.dict_for_handlers['code'] = int(code) + + +def stream_data_received(session, + stream_id: int, + data: bytes, + stream_ended: bool): + code: int = session.dict_for_handlers['code'] + if session.stream_is_unidirectional(stream_id): + session.stop_stream(stream_id, code) + else: + session.stop_stream(stream_id, code) + session.reset_stream(stream_id, code)
\ No newline at end of file diff --git a/testing/web-platform/tests/webtransport/handlers/client-close.py b/testing/web-platform/tests/webtransport/handlers/client-close.py new file mode 100644 index 0000000000..01fb14b134 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/client-close.py @@ -0,0 +1,59 @@ +from typing import Optional, Tuple +from urllib.parse import urlsplit, parse_qsl + + +def session_established(session): + path: Optional[bytes] = None + for key, value in session.request_headers: + if key == b':path': + path = value + assert path is not None + qs = dict(parse_qsl(urlsplit(path).query)) + token = qs[b'token'] + if token is None: + raise Exception('token is missing, path = {}'.format(path)) + session.dict_for_handlers['token'] = token + session.create_bidirectional_stream() + + +def stream_reset(session, stream_id: int, error_code: int) -> None: + token = session.dict_for_handlers['token'] + data = session.stash.take(key=token) or {} + + data['stream-close-info'] = { + 'source': 'reset', + 'code': error_code + } + session.stash.put(key=token, value=data) + + +def stream_data_received(session, + stream_id: int, + data: bytes, + stream_ended: bool): + if stream_ended: + token = session.dict_for_handlers['token'] + stashed_data = session.stash.take(key=token) or {} + stashed_data['stream-close-info'] = { + 'source': 'FIN', + } + session.stash.put(key=token, value=stashed_data) + + +def session_closed( + session, close_info: Optional[Tuple[int, bytes]], abruptly: bool) -> None: + token = session.dict_for_handlers['token'] + data = session.stash.take(key=token) or {} + + decoded_close_info: Optional[Dict[str, Any]] = None + if close_info: + decoded_close_info = { + 'code': close_info[0], + 'reason': close_info[1].decode() + } + + data['session-close-info'] = { + 'abruptly': abruptly, + 'close_info': decoded_close_info + } + session.stash.put(key=token, value=data) diff --git a/testing/web-platform/tests/webtransport/handlers/custom-response.py b/testing/web-platform/tests/webtransport/handlers/custom-response.py new file mode 100644 index 0000000000..05e4c4ba36 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/custom-response.py @@ -0,0 +1,14 @@ +from urllib.parse import urlsplit, parse_qsl + + +def connect_received(request_headers, response_headers): + for data in request_headers: + if data[0] == b':path': + path = data[1].decode('utf-8') + + qs = dict(parse_qsl(urlsplit(path).query)) + for key, value in qs.items(): + response_headers.append((key.encode('utf-8'), value.encode('utf-8'))) + + break + return diff --git a/testing/web-platform/tests/webtransport/handlers/echo-request-headers.py b/testing/web-platform/tests/webtransport/handlers/echo-request-headers.py new file mode 100644 index 0000000000..122d6f0601 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/echo-request-headers.py @@ -0,0 +1,11 @@ +import json + + +def session_established(session): + headers = {} + for name, value in session.request_headers: + headers[name.decode('utf-8')] = value.decode('utf-8') + + stream_id = session.create_unidirectional_stream() + data = json.dumps(headers).encode('utf-8') + session.send_stream_data(stream_id, data, end_stream=True) diff --git a/testing/web-platform/tests/webtransport/handlers/echo.py b/testing/web-platform/tests/webtransport/handlers/echo.py new file mode 100644 index 0000000000..4347d4aae3 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/echo.py @@ -0,0 +1,33 @@ +streams_dict = {} + + +def session_established(session): + # When a WebTransport session is established, a bidirectional stream is + # created by the server, which is used to echo back stream data from the + # client. + session.create_bidirectional_stream() + + +def stream_data_received(session, + stream_id: int, + data: bytes, + stream_ended: bool): + # If a stream is unidirectional, create a new unidirectional stream and echo + # back the data on that stream. + if session.stream_is_unidirectional(stream_id): + if (session.session_id, stream_id) not in streams_dict.keys(): + new_stream_id = session.create_unidirectional_stream() + streams_dict[(session.session_id, stream_id)] = new_stream_id + session.send_stream_data(streams_dict[(session.session_id, stream_id)], + data, + end_stream=stream_ended) + if (stream_ended): + del streams_dict[(session.session_id, stream_id)] + return + # Otherwise (e.g. if the stream is bidirectional), echo back the data on the + # same stream. + session.send_stream_data(stream_id, data, end_stream=stream_ended) + + +def datagram_received(session, data: bytes): + session.send_datagram(data) diff --git a/testing/web-platform/tests/webtransport/handlers/query.py b/testing/web-platform/tests/webtransport/handlers/query.py new file mode 100644 index 0000000000..75d458255a --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/query.py @@ -0,0 +1,19 @@ +from typing import Optional +from urllib.parse import urlsplit, parse_qsl +import json + + +def session_established(session): + path: Optional[bytes] = None + for key, value in session.request_headers: + if key == b':path': + path = value + assert path is not None + qs = dict(parse_qsl(urlsplit(path).query)) + token = qs[b'token'] + if token is None: + raise Exception('token is missing, path = {}'.format(path)) + + stream_id = session.create_unidirectional_stream() + data = json.dumps(session.stash.take(key=token) or {}).encode('utf-8') + session.send_stream_data(stream_id, data, end_stream=True) diff --git a/testing/web-platform/tests/webtransport/handlers/server-close.py b/testing/web-platform/tests/webtransport/handlers/server-close.py new file mode 100644 index 0000000000..e9d08f483c --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/server-close.py @@ -0,0 +1,16 @@ +from typing import Optional +from urllib.parse import urlsplit, parse_qsl + + +def session_established(session): + path: Optional[bytes] = None + for key, value in session.request_headers: + if key == b':path': + path = value + assert path is not None + qs = dict(parse_qsl(urlsplit(path).query)) + code = qs[b'code'] if b'code' in qs else None + reason = qs[b'reason'] if b'reason' in qs else b'' + close_info = None if code is None else (int(code), reason) + + session.close(close_info) diff --git a/testing/web-platform/tests/webtransport/handlers/server-connection-close.py b/testing/web-platform/tests/webtransport/handlers/server-connection-close.py new file mode 100644 index 0000000000..9721c67170 --- /dev/null +++ b/testing/web-platform/tests/webtransport/handlers/server-connection-close.py @@ -0,0 +1,9 @@ +def session_established(session): + session.create_bidirectional_stream() + + +def stream_data_received(session, + stream_id: int, + data: bytes, + stream_ended: bool): + session._http._quic.close()
\ No newline at end of file |