Module
whiplash/http3
src/whiplash/http3.pookaHTTP/3, HTTP over QUIC streams (RFC 9114).
QUIC already multiplexes and flow-controls, so HTTP/3 is mostly frames
on streams: one request per bidirectional stream, and three
unidirectional streams each way for control, the QPACK encoder and the
QPACK decoder. Connection follows them all, given the bytes QUIC
delivers on each stream; it never sees a packet.
Extended CONNECT for WebSockets over HTTP/3 is RFC 9220.
API reference
- enumErrorCode
- functionerror_code
- classFrame
- classData
- classHeaders
- classCancelPush
- classSettings
- classPushPromise
- classGoaway
- classMaxPushId
- classUnknown
- classHttp3Error
- enumStreamType
- functiondecode_frame
- functionencode_frame
- functionserver_settings
- functiondecoder_stream
- functiondecoder_output
- functioncancel
- classEvent
- classRequest
- classBody
- classPeerSettings
- classPeerGoaway
- classRequestTrailers
- classStreamEnd
- classConnection
- functionserver
- functionreceive
- functionrespond
- functionrespond_on
- functionencoder_stream
- functionencoder_output
- functiondata
enum ErrorCode
The error codes of RFC 9114 section 8.1.
ErrorCode.NoError
ErrorCode.GeneralProtocolError
ErrorCode.InternalError
ErrorCode.StreamCreationError
ErrorCode.ClosedCriticalStream
ErrorCode.FrameUnexpected
ErrorCode.FrameError
ErrorCode.ExcessiveLoad
ErrorCode.IdError
ErrorCode.SettingsError
ErrorCode.MissingSettings
ErrorCode.RequestRejected
ErrorCode.RequestCancelled
ErrorCode.RequestIncomplete
ErrorCode.MessageError
ErrorCode.ConnectError
ErrorCode.VersionFallback
ErrorCode.QpackDecompressionFailed
ErrorCode.QpackEncoderStreamError
ErrorCode.QpackDecoderStreamError
error_code(code: ErrorCode) -> Int
fn(whiplash/http3.ErrorCode) -> IntAn error code's number on the wire, from 0x100.
class Frame
One frame (section 7.2).
class Data(data: BitArray) is Frame
data: BitArray
BitArray
fn(BitArray) -> whiplash/http3.Dataclass Headers(section: BitArray) is Frame
section: BitArray
BitArray
fn(BitArray) -> whiplash/http3.Headersclass CancelPush(push: Int) is Frame
push: Int
Int
fn(Int) -> whiplash/http3.CancelPushclass Settings(settings: List(#(Int, Int))) is Frame
settings: List(#(Int, Int))
List(#(Int, Int))
fn(List(#(Int, Int))) -> whiplash/http3.Settingsclass PushPromise(push: Int, section: BitArray) is Frame
push: Int
Intsection: BitArray
BitArray
fn(Int, BitArray) -> whiplash/http3.PushPromiseclass Goaway(id: Int) is Frame
id: Int
Int
fn(Int) -> whiplash/http3.Goawayclass MaxPushId(push: Int) is Frame
push: Int
Int
fn(Int) -> whiplash/http3.MaxPushIdclass Unknown(kind: Int, payload: BitArray) is Frame
A frame of a type this end does not know, including the reserved "grease" types 0x1f * N + 0x21, which must be ignored.
kind: Int
Intpayload: BitArray
BitArray
fn(Int, BitArray) -> whiplash/http3.Unknownclass Http3Error(code: ErrorCode, message: String)
A connection or stream error.
code: ErrorCode
whiplash/http3.ErrorCodemessage: String
String
fn(whiplash/http3.ErrorCode, String) -> whiplash/http3.Http3Errorenum StreamType
The types of unidirectional streams (section 6.2).
StreamType.Control
StreamType.Push
StreamType.QpackEncoder
StreamType.QpackDecoder
decode_frame(bytes: BitArray) -> Result(Option(#(Frame, BitArray)), Http3Error)
fn(BitArray) -> Result(Option(#(whiplash/http3.Frame, BitArray)), whiplash/http3.Http3Error)One frame from the front of the bytes, and the rest. Ok(None) when it
has not fully arrived.
encode_frame(frame: Frame) -> BitArray
fn(whiplash/http3.Frame) -> BitArrayserver_settings() -> List(#(Int, Int))
fn() -> List(#(Int, Int))What a server announces: a 4 KiB QPACK dynamic table for the client's encoder, up to 16 request streams blocked on it, and extended CONNECT (RFC 9220).
decoder_stream() -> Int
fn() -> IntThe server's QPACK decoder stream: the second unidirectional stream it opens, after the control stream (3).
decoder_output(connection: Connection) -> #(BitArray, Connection)
fn(whiplash/http3.Connection) -> #(BitArray, whiplash/http3.Connection)Bytes for the server's QPACK decoder stream (RFC 9204 section 4.4): the
stream type the first time, then Section Acknowledgements, Stream
Cancellations and Insert Count Increments as field sections are decoded
and insertions arrive. Send them on decoder_stream(); empty when there
is nothing new.
let #(bytes, h3) = http3.decoder_output(h3)
let c = quic.send(c, http3.decoder_stream(), bytes, False)
cancel(connection: Connection, stream: Int) -> Connection
fn(whiplash/http3.Connection, Int) -> whiplash/http3.ConnectionThe client abandoned a request stream: forget it, and if its HEADERS were waiting for insertions, tell the client's encoder (Stream Cancellation) so it stops counting on them.
class Event
What happened, as the server sees it.
class Request(stream: Int, fields: List(Field), end_stream: Bool) is Event
stream: Int
Intfields: List(Field)
List(whiplash/hpack.Field)end_stream: Bool
Bool
fn(Int, List(whiplash/hpack.Field), Bool) -> whiplash/http3.Requestclass Body(stream: Int, data: BitArray, end_stream: Bool) is Event
stream: Int
Intdata: BitArray
BitArrayend_stream: Bool
Bool
fn(Int, BitArray, Bool) -> whiplash/http3.Bodyclass PeerSettings(settings: List(#(Int, Int))) is Event
settings: List(#(Int, Int))
List(#(Int, Int))
fn(List(#(Int, Int))) -> whiplash/http3.PeerSettingsclass PeerGoaway(id: Int) is Event
id: Int
Int
fn(Int) -> whiplash/http3.PeerGoawayclass RequestTrailers(stream: Int, fields: List(Field)) is Event
stream: Int
Intfields: List(Field)
List(whiplash/hpack.Field)
fn(Int, List(whiplash/hpack.Field)) -> whiplash/http3.RequestTrailersclass StreamEnd(stream: Int) is Event
FIN arriving separately, or following trailers/ignored extension frames.
stream: Int
Int
fn(Int) -> whiplash/http3.StreamEndclass Connection(
decoder: qpack.Decoder,
peer_settings: Option(List(#(Int, Int))),
control_stream: Option(Int),
streams: Dict(Int, _Stream),
encoder_stream: Option(Int),
decoder_stream: Option(Int),
peer_goaway: Option(Int),
closed: List(Int),
last_request: Int,
going_away: Bool,
max_push: Int,
qpack: _Qpack
)
One server-side HTTP/3 connection, above QUIC.
decoder: qpack.Decoder
whiplash/qpack.Decoderpeer_settings: Option(List(#(Int, Int)))
Option(List(#(Int, Int)))control_stream: Option(Int)
Option(Int)streams: Dict(Int, _Stream)
$package/pooka_stdlib/pooka/dict.Dict(Int, whiplash/http3._Stream)encoder_stream: Option(Int)
Option(Int)decoder_stream: Option(Int)
Option(Int)peer_goaway: Option(Int)
Option(Int)closed: List(Int)
List(Int)last_request: Int
Intgoing_away: Bool
Boolmax_push: Int
Intqpack: _Qpack
whiplash/http3._Qpack
fn(whiplash/qpack.Decoder, Option(List(#(Int, Int))), Option(Int), $package/pooka_stdlib/pooka/dict.Dict(Int, whiplash/http3._Stream), Option(Int), Option(Int), Option(Int), List(Int), Int, Bool, Int, whiplash/http3._Qpack) -> whiplash/http3.Connectionserver() -> #(Connection, BitArray)
fn() -> #(whiplash/http3.Connection, BitArray)A connection, and the bytes for the server's control stream: its type, then SETTINGS.
receive(connection: Connection, stream: Int, bytes: BitArray, fin: Bool) -> Result(
#(List(Event), Connection),
Http3Error
)
fn(whiplash/http3.Connection, Int, BitArray, Bool) -> Result(#(List(whiplash/http3.Event), whiplash/http3.Connection), whiplash/http3.Http3Error)Bytes QUIC delivered on a stream, with whether the stream ended.
respond(status: Int, headers: List(Field)) -> BitArray
fn(Int, List(whiplash/hpack.Field)) -> BitArrayA response's HEADERS frame, encoded with QPACK's static table.
respond_on(
connection: Connection,
stream: Int,
status: Int,
headers: List(Field)
) -> #(BitArray, Connection)
fn(whiplash/http3.Connection, Int, Int, List(whiplash/hpack.Field)) -> #(BitArray, whiplash/http3.Connection)A response's HEADERS frame on stream, encoded with QPACK's dynamic
table where the client allows one: fields it has acknowledged go as one
indexed line, and fields worth repeating are inserted for later responses
(see encoder_output).
let #(head, h3) = http3.respond_on(h3, stream, 200, headers)
encoder_stream() -> Int
fn() -> IntThe server's QPACK encoder stream: the third unidirectional stream it opens, after the control (3) and decoder (7) streams.
encoder_output(connection: Connection) -> #(BitArray, Connection)
fn(whiplash/http3.Connection) -> #(BitArray, whiplash/http3.Connection)Bytes for the server's QPACK encoder stream (RFC 9204 section 4.3): its
type and the table capacity once the client's SETTINGS allow a table, then
insertions. Send them on encoder_stream() before the responses that
follow; empty when there is nothing new.
data(bytes: BitArray) -> BitArray
fn(BitArray) -> BitArrayA DATA frame.