1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# WebTransport in web-platform-tests
This document describes [WebTransport](https://datatracker.ietf.org/wg/webtrans/documents/) support in web-platform-tests.
## WebTransport over HTTP/3
`tools/webtransport` provides a simple
[WebTransport over HTTP/3](https://datatracker.ietf.org/doc/draft-ietf-webtrans-http3/) server for testing. The server interprets the underlying protocols (WebTransport, HTTP/3 and QUIC) and manages webtransport sessions. When the server receives a request (extended CONNECT method) from a client the server looks up a corresponding webtransport handler based on the `:path` header value, then delegates actual tasks to the handler. Handlers are typically located under `webtransport/handlers`.
### Handlers
A WebTransport handler is a python script which contains callback functions. Callback functions are called every time a WebTransport event happens. Definitions of all callback can be found the [APIs section](#APIs).
The following is an example handler which echos back received data.
```python
def stream_data_received(session, stream_id: int, data: bytes, stream_ended: bool):
if session.stream_is_unidirectional(stream_id):
return
session.send_stream_data(stream_id, data)
def datagram_received(session, data: bytes):
session.send_datagram(data)
```
`session` is a `WebTransportSession` object that represents a WebTransport over HTTP/3 session. It provides APIs to handle the session.
### Handler APIs
#### `connection_received(request_headers, response_headers)`
Called whenever an extended CONNECT method is received.
- <b>Parameters</b>
- <b>request_headers</b>: The request headers received from the peer.
- <b>response_headers</b>: The response headers which will be sent to the peer `:status` is set to 200 when it isn't specified.
---
#### `session_established(session)`
Called whenever a WebTransport session is established.
- <b>Parameters</b>
- <b>session</b>: A WebTransport session object.
---
#### `stream_data_received(session, stream_id, data, stream_ended)`
Called whenever data is received on a WebTransport stream.
- <b>Parameters</b>
- <b>session</b>: A WebTransport session object.
- <b>stream_id</b>: The ID of the stream.
- <b>data</b>: The received data.
- <b>stream_ended</b>: Whether the stream is ended.
---
#### `datagram_received(session, data)`
Called whenever a datagram is received on a WebTransport session.
- <b>Parameters</b>
- <b>session</b>: A WebTransport session object.
- <b>data</b>: The received data.
---
#### `stream_reset(session, stream_id, error_code)`
Called whenever a datagram is reset with RESET_STREAM.
- <b>Parameters</b>
- <b>session</b>: A WebTransport session object.
- <b>stream_id</b>: The ID of the stream.
- <b>error_code</b>: The reason of the reset.
|