Module

whiplash/qpack

src/whiplash/qpack.pooka

QPACK, 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

class

QpackError

src/whiplash/qpack.pooka:29
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).

field

code

src/whiplash/qpack.pooka:29
code: Int
INFERREDInt
field

message

src/whiplash/qpack.pooka:29
message: String
INFERREDString
constructor

new

src/whiplash/qpack.pooka:29
INFERREDfn(Int, String) -> whiplash/qpack.QpackError
class

Instruction

src/whiplash/qpack.pooka:32
class Instruction

An instruction on the encoder stream (section 4.3).

class

SetCapacity

src/whiplash/qpack.pooka:34
class SetCapacity(capacity: Int) is Instruction
field

capacity

src/whiplash/qpack.pooka:34
capacity: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:34
INFERREDfn(Int) -> whiplash/qpack.SetCapacity
class

InsertWithNameReference

src/whiplash/qpack.pooka:36
class InsertWithNameReference(static: Bool, index: Int, value: String) is Instruction
field

static

src/whiplash/qpack.pooka:36
static: Bool
INFERREDBool
field

index

src/whiplash/qpack.pooka:36
index: Int
INFERREDInt
field

value

src/whiplash/qpack.pooka:36
value: String
INFERREDString
constructor

new

src/whiplash/qpack.pooka:36
INFERREDfn(Bool, Int, String) -> whiplash/qpack.InsertWithNameReference
class

InsertWithLiteralName

src/whiplash/qpack.pooka:38
class InsertWithLiteralName(name: String, value: String) is Instruction
field

name

src/whiplash/qpack.pooka:38
name: String
INFERREDString
field

value

src/whiplash/qpack.pooka:38
value: String
INFERREDString
constructor

new

src/whiplash/qpack.pooka:38
INFERREDfn(String, String) -> whiplash/qpack.InsertWithLiteralName
class

Duplicate

src/whiplash/qpack.pooka:40
class Duplicate(index: Int) is Instruction
field

index

src/whiplash/qpack.pooka:40
index: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:40
INFERREDfn(Int) -> whiplash/qpack.Duplicate
class

Acknowledgement

src/whiplash/qpack.pooka:43
class Acknowledgement

An instruction on the decoder stream (section 4.4).

class

SectionAcknowledgement

src/whiplash/qpack.pooka:45
class SectionAcknowledgement(stream: Int) is Acknowledgement
field

stream

src/whiplash/qpack.pooka:45
stream: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:45
class

StreamCancellation

src/whiplash/qpack.pooka:47
class StreamCancellation(stream: Int) is Acknowledgement
field

stream

src/whiplash/qpack.pooka:47
stream: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:47
class

InsertCountIncrement

src/whiplash/qpack.pooka:49
class InsertCountIncrement(increment: Int) is Acknowledgement
field

increment

src/whiplash/qpack.pooka:49
increment: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:49
class

Entry

src/whiplash/qpack.pooka:53
class 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).

field

name

src/whiplash/qpack.pooka:53
name: String
INFERREDString
field

value

src/whiplash/qpack.pooka:53
value: String
INFERREDString
field

name_size

src/whiplash/qpack.pooka:53
name_size: Int
INFERREDInt
field

value_size

src/whiplash/qpack.pooka:53
value_size: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:53
INFERREDfn(String, String, Int, Int) -> whiplash/qpack.Entry
class

Decoder

src/whiplash/qpack.pooka:57
class Decoder(
  entries: List(Entry),
  size: Int,
  capacity: Int,
  max_capacity: Int,
  insert_count: Int,
  max_blocked: Int
)
field

entries

src/whiplash/qpack.pooka:58
entries: List(Entry)
INFERREDList(whiplash/qpack.Entry)
field

size

src/whiplash/qpack.pooka:59
size: Int
INFERREDInt
field

capacity

src/whiplash/qpack.pooka:60
capacity: Int
INFERREDInt
field

max_capacity

src/whiplash/qpack.pooka:61
max_capacity: Int
INFERREDInt
field

insert_count

src/whiplash/qpack.pooka:62
insert_count: Int
INFERREDInt
field

max_blocked

src/whiplash/qpack.pooka:63
max_blocked: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:58
INFERREDfn(List(whiplash/qpack.Entry), Int, Int, Int, Int, Int) -> whiplash/qpack.Decoder
class

Decoded

src/whiplash/qpack.pooka:67
class Decoded

A field section, decoded, or waiting for insertions.

class

Fields

src/whiplash/qpack.pooka:69
class Fields(fields: List(Field)) is Decoded
field

fields

src/whiplash/qpack.pooka:69
fields: List(Field)
INFERREDList(whiplash/hpack.Field)
constructor

new

src/whiplash/qpack.pooka:69
class

Blocked

src/whiplash/qpack.pooka:71
class Blocked(required_insert_count: Int) is Decoded
field

required_insert_count

src/whiplash/qpack.pooka:71
required_insert_count: Int
INFERREDInt
constructor

new

src/whiplash/qpack.pooka:71
INFERREDfn(Int) -> whiplash/qpack.Blocked
function

decoder

src/whiplash/qpack.pooka:75
decoder(max_capacity: Int, max_blocked: Int) -> Decoder
INFERREDfn(Int, Int) -> whiplash/qpack.Decoder

A decoder allowed max_capacity octets of dynamic table and max_blocked blocked streams.

function

static_entry

src/whiplash/qpack.pooka:80
static_entry(index: Int) -> Option(#(String, String))
INFERREDfn(Int) -> Option(#(String, String))

The indexth entry of the static table, from 0 to 98 (Appendix A).

function

decode_section

src/whiplash/qpack.pooka:85
decode_section(decoder: Decoder, stream: Int, section: BitArray) -> Result(
  #(Decoded, List(Acknowledgement)),
  QpackError
)

Decode one field section from a request or push stream.

function

receive_instructions

src/whiplash/qpack.pooka:96
receive_instructions(decoder: Decoder, bytes: BitArray) -> Result(
  #(Decoder, BitArray),
  QpackError
)
INFERREDfn(whiplash/qpack.Decoder, BitArray) -> Result(#(whiplash/qpack.Decoder, BitArray), whiplash/qpack.QpackError)

Read instructions from the encoder stream, and apply them.

function

encode_static

src/whiplash/qpack.pooka:114
encode_static(fields: List(Field)) -> BitArray
INFERREDfn(List(whiplash/hpack.Field)) -> BitArray

Encode a field section using only the static table and literals: no encoder stream, never blocking. This is what a server needs first.

function

encode_acknowledgement

src/whiplash/qpack.pooka:119
encode_acknowledgement(acknowledgement: Acknowledgement) -> BitArray
INFERREDfn(whiplash/qpack.Acknowledgement) -> BitArray

One decoder-stream instruction's bytes.

function

encode_instruction

src/whiplash/qpack.pooka:131
encode_instruction(instruction: Instruction) -> BitArray
INFERREDfn(whiplash/qpack.Instruction) -> BitArray

One encoder-stream instruction's bytes.

function

decode_required_insert_count

src/whiplash/qpack.pooka:152
decode_required_insert_count(encoded: Int, max_entries: Int, total_inserts: Int) -> Result(
  Int,
  QpackError
)
INFERREDfn(Int, Int, Int) -> Result(Int, whiplash/qpack.QpackError)

Required Insert Count from its encoded form (section 4.5.1.1).

function

decode_acknowledgements

src/whiplash/qpack.pooka:647
decode_acknowledgements(bytes: BitArray) -> Result(
  #(List(Acknowledgement), BitArray),
  QpackError
)
INFERREDfn(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

src/whiplash/qpack.pooka:697
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.

field

capacity

src/whiplash/qpack.pooka:698
capacity: Int
INFERREDInt
field

max_entries

src/whiplash/qpack.pooka:699
max_entries: Int
INFERREDInt
field

entries

src/whiplash/qpack.pooka:700
entries: List(#(String, String, Int))
INFERREDList(#(String, String, Int))
field

size

src/whiplash/qpack.pooka:701
size: Int
INFERREDInt
field

inserted

src/whiplash/qpack.pooka:702
inserted: Int
INFERREDInt
field

known

src/whiplash/qpack.pooka:703
known: Int
INFERREDInt
field

sections

src/whiplash/qpack.pooka:704
sections: Dict(Int, List(#(Int, Int)))
INFERRED$package/pooka_stdlib/pooka/dict.Dict(Int, List(#(Int, Int)))
constructor

new

src/whiplash/qpack.pooka:698
INFERREDfn(Int, Int, List(#(String, String, Int)), Int, Int, Int, $package/pooka_stdlib/pooka/dict.Dict(Int, List(#(Int, Int)))) -> whiplash/qpack.Encoder
function

encoder

src/whiplash/qpack.pooka:708
encoder() -> Encoder
INFERREDfn() -> whiplash/qpack.Encoder

An encoder with no dynamic table, until the peer allows one.

function

use_capacity

src/whiplash/qpack.pooka:715
use_capacity(encoder: Encoder, maximum: Int) -> #(Encoder, BitArray)
INFERREDfn(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.

function

encode_section

src/whiplash/qpack.pooka:742
encode_section(encoder: Encoder, stream: Int, fields: List(Field)) -> #(
  BitArray,
  BitArray,
  Encoder
)
INFERREDfn(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.

Pooka
let #(section, instructions, encoder) = qpack.encode_section(encoder, 0, fields)
function

acknowledge

src/whiplash/qpack.pooka:971
acknowledge(encoder: Encoder, acknowledgements: List(Acknowledgement)) -> Result(
  Encoder,
  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.