Module
whiplash/qpack
src/whiplash/qpack.pookaQPACK, HPACK's cousin for HTTP/3 (RFC 9204).
HTTP/3 streams arrive out of order, so the dynamic table is filled on its own unidirectional encoder stream, and each field section says how many insertions it needs. A section that needs more than have arrived is blocked until they do.
Integers and Huffman coding are HPACK's, from whiplash/hpack. Both
directions use the dynamic table: Decoder follows the peer's encoder,
blocked sections included, and Encoder fills a table for the peer from
fields worth repeating, referencing only what the peer has acknowledged.
API reference
- classQpackError
- classInstruction
- classSetCapacity
- classInsertWithNameReference
- classInsertWithLiteralName
- classDuplicate
- classAcknowledgement
- classSectionAcknowledgement
- classStreamCancellation
- classInsertCountIncrement
- classEntry
- classDecoder
- classDecoded
- classFields
- classBlocked
- functiondecoder
- functionstatic_entry
- functiondecode_section
- functionreceive_instructions
- functionencode_static
- functionencode_acknowledgement
- functionencode_instruction
- functiondecode_required_insert_count
- functiondecode_acknowledgements
- classEncoder
- functionencoder
- functionuse_capacity
- functionencode_section
- functionacknowledge
class QpackError(code: Int, message: String)
Why a field section or an encoder instruction was refused: QPACK_DECOMPRESSION_FAILED, QPACK_ENCODER_STREAM_ERROR or QPACK_DECODER_STREAM_ERROR (section 6).
code: Int
Intmessage: String
String
fn(Int, String) -> whiplash/qpack.QpackErrorclass Instruction
An instruction on the encoder stream (section 4.3).
class SetCapacity(capacity: Int) is Instruction
capacity: Int
Int
fn(Int) -> whiplash/qpack.SetCapacityclass InsertWithNameReference(static: Bool, index: Int, value: String) is Instruction
static: Bool
Boolindex: Int
Intvalue: String
String
fn(Bool, Int, String) -> whiplash/qpack.InsertWithNameReferenceclass InsertWithLiteralName(name: String, value: String) is Instruction
name: String
Stringvalue: String
String
fn(String, String) -> whiplash/qpack.InsertWithLiteralNameclass Duplicate(index: Int) is Instruction
index: Int
Int
fn(Int) -> whiplash/qpack.Duplicateclass Acknowledgement
An instruction on the decoder stream (section 4.4).
class SectionAcknowledgement(stream: Int) is Acknowledgement
stream: Int
Int
fn(Int) -> whiplash/qpack.SectionAcknowledgementclass StreamCancellation(stream: Int) is Acknowledgement
stream: Int
Int
fn(Int) -> whiplash/qpack.StreamCancellationclass InsertCountIncrement(increment: Int) is Acknowledgement
increment: Int
Int
fn(Int) -> whiplash/qpack.InsertCountIncrementclass Entry(name: String, value: String, name_size: Int, value_size: Int)
The decoder's dynamic table and what it has been told. Original sizes survive non-UTF-8-to-text conversion (RFC 9204 3.2.1).
name: String
Stringvalue: String
Stringname_size: Int
Intvalue_size: Int
Int
fn(String, String, Int, Int) -> whiplash/qpack.Entryclass Decoder(
entries: List(Entry),
size: Int,
capacity: Int,
max_capacity: Int,
insert_count: Int,
max_blocked: Int
)
entries: List(Entry)
List(whiplash/qpack.Entry)size: Int
Intcapacity: Int
Intmax_capacity: Int
Intinsert_count: Int
Intmax_blocked: Int
Int
fn(List(whiplash/qpack.Entry), Int, Int, Int, Int, Int) -> whiplash/qpack.Decoderclass Decoded
A field section, decoded, or waiting for insertions.
class Fields(fields: List(Field)) is Decoded
fields: List(Field)
List(whiplash/hpack.Field)
fn(List(whiplash/hpack.Field)) -> whiplash/qpack.Fieldsclass Blocked(required_insert_count: Int) is Decoded
required_insert_count: Int
Int
fn(Int) -> whiplash/qpack.Blockeddecoder(max_capacity: Int, max_blocked: Int) -> Decoder
fn(Int, Int) -> whiplash/qpack.DecoderA decoder allowed max_capacity octets of dynamic table and
max_blocked blocked streams.
static_entry(index: Int) -> Option(#(String, String))
fn(Int) -> Option(#(String, String))The indexth entry of the static table, from 0 to 98 (Appendix A).
decode_section(decoder: Decoder, stream: Int, section: BitArray) -> Result(
#(Decoded, List(Acknowledgement)),
QpackError
)
fn(whiplash/qpack.Decoder, Int, BitArray) -> Result(#(whiplash/qpack.Decoded, List(whiplash/qpack.Acknowledgement)), whiplash/qpack.QpackError)Decode one field section from a request or push stream.
receive_instructions(decoder: Decoder, bytes: BitArray) -> Result(
#(Decoder, BitArray),
QpackError
)
fn(whiplash/qpack.Decoder, BitArray) -> Result(#(whiplash/qpack.Decoder, BitArray), whiplash/qpack.QpackError)Read instructions from the encoder stream, and apply them.
encode_static(fields: List(Field)) -> BitArray
fn(List(whiplash/hpack.Field)) -> BitArrayEncode a field section using only the static table and literals: no encoder stream, never blocking. This is what a server needs first.
encode_acknowledgement(acknowledgement: Acknowledgement) -> BitArray
fn(whiplash/qpack.Acknowledgement) -> BitArrayOne decoder-stream instruction's bytes.
encode_instruction(instruction: Instruction) -> BitArray
fn(whiplash/qpack.Instruction) -> BitArrayOne encoder-stream instruction's bytes.
decode_required_insert_count(encoded: Int, max_entries: Int, total_inserts: Int) -> Result(
Int,
QpackError
)
fn(Int, Int, Int) -> Result(Int, whiplash/qpack.QpackError)Required Insert Count from its encoded form (section 4.5.1.1).
decode_acknowledgements(bytes: BitArray) -> Result(
#(List(Acknowledgement), BitArray),
QpackError
)
fn(BitArray) -> Result(#(List(whiplash/qpack.Acknowledgement), BitArray), whiplash/qpack.QpackError)Incremental decoder-stream instructions. Retain returned bytes when an integer crosses a delivery boundary; malformed encodings use error 0x202.
class Encoder(
capacity: Int,
max_entries: Int,
entries: List(#(String, String, Int)),
size: Int,
inserted: Int,
known: Int,
sections: Dict(Int, List(#(Int, Int)))
)
This end's encoder: the dynamic table it fills for the peer's decoder
(RFC 9204 section 2.1). Sections reference only entries the peer has
acknowledged, so they never block. Entries are newest first, with their
sizes; inserted counts every insertion, known is the Known Received
Count, and sections holds, per stream, the Required Insert Count and the
oldest entry referenced of each section not yet acknowledged (oldest
first). Entries they reference are never evicted.
capacity: Int
Intmax_entries: Int
Intentries: List(#(String, String, Int))
List(#(String, String, Int))size: Int
Intinserted: Int
Intknown: Int
Intsections: Dict(Int, List(#(Int, Int)))
$package/pooka_stdlib/pooka/dict.Dict(Int, List(#(Int, Int)))
fn(Int, Int, List(#(String, String, Int)), Int, Int, Int, $package/pooka_stdlib/pooka/dict.Dict(Int, List(#(Int, Int)))) -> whiplash/qpack.Encoderencoder() -> Encoder
fn() -> whiplash/qpack.EncoderAn encoder with no dynamic table, until the peer allows one.
use_capacity(encoder: Encoder, maximum: Int) -> #(Encoder, BitArray)
fn(whiplash/qpack.Encoder, Int) -> #(whiplash/qpack.Encoder, BitArray)The peer's SETTINGS_QPACK_MAX_TABLE_CAPACITY arrived: use up to 4 KiB of it. Returns the encoder-stream instruction that sets the capacity, empty when the peer allows no table.
encode_section(encoder: Encoder, stream: Int, fields: List(Field)) -> #(
BitArray,
BitArray,
Encoder
)
fn(whiplash/qpack.Encoder, Int, List(whiplash/hpack.Field)) -> #(BitArray, BitArray, whiplash/qpack.Encoder)Encode a field section for stream. Fields the peer has in its table
already (acknowledged) are one indexed line; others are literals, and
fields worth remembering are inserted for later sections. Returns the
section, the encoder-stream instructions to send first, and the encoder.
let #(section, instructions, encoder) = qpack.encode_section(encoder, 0, fields)
acknowledge(encoder: Encoder, acknowledgements: List(Acknowledgement)) -> Result(
Encoder,
QpackError
)
fn(whiplash/qpack.Encoder, List(whiplash/qpack.Acknowledgement)) -> Result(whiplash/qpack.Encoder, whiplash/qpack.QpackError)Apply the peer decoder's instructions (RFC 9204 section 4.4): a Section Acknowledgement settles a stream's oldest section, a Stream Cancellation all of them, an Insert Count Increment raises the Known Received Count. Acknowledging what was never sent is QPACK_DECODER_STREAM_ERROR.