asgiref icon indicating copy to clipboard operation
asgiref copied to clipboard

Spec for WebTransport in ASGI

Open jlaine opened this issue 2 years ago • 7 comments

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!

jlaine avatar Jul 09 '21 15:07 jlaine

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.

andrewgodwin avatar Jul 09 '21 16:07 andrewgodwin

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.

jlaine avatar Jul 10 '21 00:07 jlaine

Maybe @bashi has some insights here in light of the specification work done for the Web Platform Tests?

jlaine avatar Jul 10 '21 10:07 jlaine

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.

bashi avatar Jul 11 '21 23:07 bashi

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 to websocket.connect, it expects a reply of type webtransport.accept or webtransport.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"]

jlaine avatar Jul 13 '21 10:07 jlaine

when I prototyped a WebTransport over HTTP/3 server for WPT

Is the server code published on GitHub?

guest271314 avatar Jul 18 '21 15:07 guest271314

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

jlaine avatar Jul 22 '21 21:07 jlaine