asgiref
asgiref copied to clipboard
Spec for WebTransport in ASGI
With QUIC standardisation complete (RFC 9000) and HTTP/3 nearing completion, a new spec is shaping up: WebTransport:
https://w3c.github.io/webtransport/ https://datatracker.ietf.org/doc/html/draft-vvv-webtransport-http3
This specification revolves around a "session" initiated by the client over an HTTP3 connection by means of a CONNECT method to a give path/authority. The session then provides:
- bidirectional streams (similar to WebSockets, but there can be more than one per session)
- unidirectional streams
- datagrams for message-oriented communications
I am currently working on integrating WebTransport support in aioquic, my QUIC/HTTP3 stack, so hypercorn could very soon have support for WebTransport (hi @pgjones).
See: https://github.com/aiortc/aioquic/pull/204
It would be great if there was a standardised API for Python web apps to leverage this, so I'd love us to start the discussion!
Gosh, that's a lot of spec to cover. I think a good first move here would be to implement a prototype server and play with the message format a bit until it starts to feel alright to write apps against? That's what I did with HTTP and WebSocket.
Sounds good, I'll do exactly that. The aioquic repository already features a basic HTTP/3 server which can run ASGI apps, I'll tack on a WebTransport demo.
Maybe @bashi has some insights here in light of the specification work done for the Web Platform Tests?
Unfortunately I haven't explored integration with wsgi/asgi when I prototyped a WebTransport over HTTP/3 server for WPT. This is mostly because wptserve has a design goal which gives test authors control of the exact bytes sent over the wire and their timing (See: introduction).
Current proposed WPT APIs for WebTransport over HTTP/3 can be found here. I plan to update the proposed APIs once @jlaine's work has done.
I have started putting together a demo WebTransport server with an "extended" ASGI implementation. So far the new messages I have are:
Server => ASGI app
-
webtransport.connect
: equivalent towebsocket.connect
, it expects a reply of typewebtransport.accept
orwebtransport.close
to accept or reject the CONNECT request -
webtransport.datagram.receive
: informs the ASGI app that a datagram was received. The payload is in message["data"] -
webtransport.stream.receive
: informs the ASGI app that stream data was received. The payload is in message["data"], and the stream identifier in message["stream"]
ASGI app => server
-
webtransport.accept
: accept the WebTransport session -
webtransport.close
: reject or end the WebTransport session -
webtransport.datagram.send
: send a datagram. The payload is in message["data"] -
webtransport.stream.send
: send stream data. The payload is in message["data"], and the stream identifier in message["stream"]
when I prototyped a WebTransport over HTTP/3 server for WPT
Is the server code published on GitHub?
Is the server code published on GitHub?
Yes, the http3_server.py
provided with aioquic
includes the WebTransport demo, and I've provided some instructions on how to use it in https://github.com/aiortc/aioquic/issues/163