Documentation
¶
Overview ¶
Package qpack is a QPACK (RFC 9204) encoder whose dynamic table use and Huffman rule follow a browser's, and a decoder for the peer's field sections and encoder stream.
The encoder tracks the peer's acknowledgments (Known Received Count, blocked streams) from its decoder stream and never evicts an entry the peer may still need.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlocked = errors.New("qpack: field section blocked on the encoder stream")
ErrBlocked is a field section that refers to entries the encoder stream has not inserted yet: decode it again after more encoder stream data.
var ErrDecoderStream = errors.New("qpack: decoder stream error")
ErrDecoderStream is a decoder stream instruction the encoder cannot accept: a connection error (QPACK_DECODER_STREAM_ERROR).
var ErrDecompression = errors.New("qpack: decompression failed")
ErrDecompression is a field section the decoder cannot decode: a connection error (QPACK_DECOMPRESSION_FAILED).
var ErrEncoderStream = errors.New("qpack: encoder stream error")
ErrEncoderStream is an encoder stream instruction the decoder cannot apply: a connection error (QPACK_ENCODER_STREAM_ERROR).
Functions ¶
Types ¶
type Config ¶
type Config struct {
Strategy Strategy
// HuffmanAlways codes every string with Huffman; otherwise only those
// it makes shorter.
HuffmanAlways bool
// MaxCapacity caps the dynamic table capacity the encoder sets,
// whatever the peer allows.
MaxCapacity uint64
// AnnounceCapacity sets the capacity under StrategyStatic too, which
// never inserts (Safari on iOS).
AnnounceCapacity bool
}
Config is how an encoder encodes.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes the peer's field sections and applies its encoder stream. It is not safe for concurrent use.
func NewDecoder ¶
NewDecoder returns a decoder for a connection that advertised maxCapacity as its SETTINGS_QPACK_MAX_TABLE_CAPACITY.
func (*Decoder) Decode ¶
Decode decodes a field section and returns its fields and Required Insert Count (the caller acknowledges a section whose count is not zero). It returns ErrBlocked if the section needs inserts not received yet.
The section's literal strings are decoded into one buffer and become one string, which the fields' literal names and values are slices of: one allocation for them all instead of one each.
func (*Decoder) OnEncoderStream ¶
OnEncoderStream applies the peer's encoder stream bytes. An instruction cut short is kept for the next call.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes field sections for one connection's requests and writes the encoder stream's instructions. It is not safe for concurrent use; the connection serialises its requests' encoding.
func NewEncoder ¶
NewEncoder returns an encoder with no dynamic table until the peer's SETTINGS allow one (SetPeerSettings).
func (*Encoder) Encode ¶
Encode encodes fields as the field section of a request on stream. It returns the encoder stream instructions the section needs (to be sent as the strategy orders them against the section) and the section.
func (*Encoder) OnDecoderStream ¶
OnDecoderStream applies the peer's decoder stream bytes: section acknowledgments, stream cancellations and insert count increments. An instruction cut short is kept for the next call.
func (*Encoder) RepeatCapacity ¶ added in v0.4.0
func (e *Encoder) RepeatCapacity()
RepeatCapacity sets the table's capacity again with the next instructions, though it did not change: Chrome does once a resumed connection's SETTINGS arrive (profile.QPACKResumedRepeat), after the remembered capacity's instruction, even one not sent yet.
func (*Encoder) SetPeerSettings ¶
SetPeerSettings applies the peer's SETTINGS_QPACK_MAX_TABLE_CAPACITY and SETTINGS_QPACK_BLOCKED_STREAMS: the table's capacity becomes the smallest of the peer's, the configured maximum and none for StrategyStatic (unless AnnounceCapacity), set by the encoder stream's next instruction when it changes. A connection resumed with 0-RTT calls it first with the SETTINGS remembered with its ticket; a lower capacity after it has inserted is ignored, since its entries and the sections referring to them were sized for the higher one (the caller closes such a connection, RFC 9114, section 7.2.4.2).
func (*Encoder) TakeCapacity ¶
TakeCapacity returns the Set Dynamic Table Capacity instructions the encoder has not sent yet, or nil, for an encoder stream that opens with them before any section; Encode then leaves them out.
type Field ¶
type Field struct {
Name, Value string
}
Field is a header field to encode, or one decoded.
type Strategy ¶
type Strategy int
Strategy is how an encoder uses the dynamic table.
const ( // StrategyStatic never inserts: fields the static table matches // exactly are indexed, others are literals with a static name // reference where one exists. StrategyStatic Strategy = iota // StrategyIndexAll is Chromium's (quiche's QpackEncoder): every field // without an exact static match is inserted and referenced, except that // entries in the draining oldest quarter are duplicated instead. The // base is the Required Insert Count, so every reference is relative. StrategyIndexAll // StrategyNewNames is Firefox's (neqo's): only a field whose name // neither table holds is inserted, and referenced post-base; other // fields are indexed on an exact match or literals with a name reference. StrategyNewNames )
Strategies.