9 unstable releases (3 breaking)
0.10.0 |
|
---|---|
0.4.0 | Dec 3, 2024 |
0.3.4 | Oct 27, 2024 |
0.3.1 | Jul 25, 2024 |
#212 in Web programming
1,396 downloads per month
Used in 16 crates
(3 directly)
115KB
2.5K
SLoC
web-transport-quinn
A wrapper around the Quinn API, abstracting away the annoying HTTP/3 internals. Provides a QUIC-like API but with web support!
WebTransport
WebTransport is a new web API that allows for low-level, bidirectional communication between a client and a server. It's available in the browser as an alternative to HTTP and WebSockets.
WebTransport is layered on top of HTTP/3 which itself is layered on top of QUIC. This library hides that detail and exposes only the QUIC API, delegating as much as possible to the underlying QUIC implementation (Quinn).
QUIC provides two primary APIs:
Streams
QUIC streams are ordered, reliable, flow-controlled, and optionally bidirectional. Both endpoints can create and close streams (including an error code) with no overhead. You can think of them as TCP connections, but shared over a single QUIC connection.
Datagrams
QUIC datagrams are unordered, unreliable, and not flow-controlled. Both endpoints can send datagrams below the MTU size (~1.2kb minimum) and they might arrive out of order or not at all. They are basically UDP packets, except they are encrypted and congestion controlled.
Usage
To use web-transport-quinn, first you need to create a quinn::Endpoint; see the documentation and examples for more information.
The only requirement is that the ALPN is set to web_transport_quinn::ALPN
(aka h3
).
Afterwards, you use web_transport_quinn::accept (as a server) or web_transport_quinn::connect (as a client) to establish a WebTransport session. This will take over the QUIC connection and perform the boring HTTP/3 handshake for you.
See the examples or moq-native for a full setup.
// Create a QUIC client.
let mut endpoint = quinn::Endpoint::client("[::]:0".parse()?)?;
endpoint.set_default_client_config(/* ... */);
// Connect to the given URL.
let session = web_transport_quinn::connect(&client, &"https://localhost").await?;
// Create a bidirectional stream.
let (mut send, mut recv) = session.open_bi().await?;
// Send a message.
send.write(b"hello").await?;
API
The web-transport-quinn
API is almost identical to the Quinn API, except that Connection is called Session.
When possible, Deref
is used to expose the underlying Quinn API.
However some of the API is wrapped or unavailable due to WebTransport limitations.
- Stream IDs are not avaialble.
- Error codes are not full VarInts (62-bits) and significantly smaller.
Dependencies
~15–26MB
~477K SLoC