WebTransport sessions
editA WebTransport session is an extended CONNECT request on an HTTP/3 connection. See Getting started for a complete example.
Client
WebTransportSession.ConnectAsync opens a QUIC connection to the host of the https URL, checks that the server supports WebTransport, and sends the CONNECT request. WebTransportClientOptions sets:
Headers: headers added to the request, such asorigin.Protocols: the application protocols the client offers. The server picks one, in Protocol.ServerCertificateHashes: the SHA-256 hashes of the certificates to accept instead of validating the certificate against the trusted roots. As in the browsers, the certificate must also be valid now, for at most 14 days.
A rejected request throws a WebTransportException whose StatusCode is the status of the response.
Server
WebTransportListener.AcceptAsync returns the next WebTransportSessionRequest: its path, its headers and the protocols the client offers. Accept it with AcceptAsync, with the protocol you pick and response headers, or reject it with RejectAsync and a status code. A connection can carry several sessions: the listener advertises MaxIncomingStreams as its maximum number of sessions (SETTINGS_WEBTRANSPORT_MAX_SESSIONS), since each session is a request stream.
Streams and datagrams
- OpenBidirectionalStreamAsync, OpenUnidirectionalStreamAsync and AcceptStreamAsync work in both directions.
- WebTransportStream.Abort takes a 32-bit application error code, which the peer reads in StreamErrorCode.
- SendDatagramAsync sends at most MaxDatagramSize bytes; the size can grow during the session.
Close and drain
- CloseAsync closes the session with an error code and a reason of at most 1024 bytes. The streams of the session are aborted.
- Closed completes with the code and the reason of the peer, or
0and an empty reason when the peer ends the session without one. It faults when the session ends abruptly: the connection is lost, or the CONNECT stream is reset. - DrainAsync asks the peer to end the session, and Draining completes when the peer asks.