hpack

package
v0.366.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package hpack decodes HPACK-compressed HTTP/2 header blocks per RFC 7541.

Wrap-vs-native judgement

Native. RFC 7541 is fully public; HPACK uses no
cryptography and no third-party libraries. The wire
format is a compact bit-packed stream of five
representation types (indexed header, literal with /
without indexing, never indexed, dynamic table size
update), variable-length integer encoding, and an
optional Huffman layer over the same canonical Appendix
B code book. Operators paste a HEADERS / CONTINUATION /
PUSH_PROMISE frame body (the HPACK block bytes surfaced
by `http2_frame_decode`) and inspect each header field
plus the per-field representation choice.

What this package covers

  • **Five representation types** per RFC 7541 §6:

  • Indexed Header Field (1xxxxxxx prefix) — references the static (1-61) or dynamic table by index; both name + value come from the table.

  • Literal with Incremental Indexing (01xxxxxx) — name indexed OR literal, value literal; entry is added to the dynamic table.

  • Literal without Indexing (0000xxxx) — name indexed OR literal, value literal; entry is NOT added.

  • Literal Never Indexed (0001xxxx) — same as without indexing, plus a 'never index in any hop' hint.

  • Dynamic Table Size Update (001xxxxx) — change max dynamic table size.

  • **N-bit prefix integer encoding** (RFC 7541 §5.1) — small values fit in the prefix bits; large values use a continuation chain in which each octet contributes 7 bits with the high bit signalling 'more octets follow'.

  • **Literal string** (RFC 7541 §5.2) — optional H bit (high bit of length byte) signals Huffman-encoded; the bytes are then either raw octets or a Huffman-encoded stream over the canonical 257-symbol Appendix B table.

  • **Static table** (Appendix A, 61 entries) — pre-baked into the decoder.

  • **Dynamic table** — newly-indexed headers are appended in the order encoded; per RFC 7541 §2.3.3 the first entry inserted gets the lowest index above the static table (62). The dynamic table is per-Decoder instance so a single `Decode` call evolves it as it consumes headers.

  • **Huffman decoder** — bit-trie walker over the Appendix B codes. Trailing partial-byte padding must be a strict prefix of the EOS code (all-ones); EOS in mid-stream is an error.

What this package does NOT cover (deliberately out of scope)

  • HPACK encoding (the inverse direction) — operators who need to craft requests have plenty of higher-level tools.

  • Cross-frame dynamic-table continuity — each `Decode` call starts with an empty dynamic table. A multi-frame session-tracker would need to feed CONTINUATION / subsequent HEADERS bytes back into the same decoder instance.

  • Header validation (e.g. lower-case constraint per RFC 9113 §8.2.1, pseudo-header rules) — names + values are surfaced verbatim; semantic validation belongs in a separate Spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder holds dynamic-table state. For a one-shot Decode the outer Decode function constructs a fresh Decoder.

type Header struct {
	Name           string `json:"name"`
	Value          string `json:"value"`
	Representation string `json:"representation"`
	Indexed        bool   `json:"indexed,omitempty"`
}

Header is one decoded HTTP/2 header field plus a hint on how it was encoded on the wire.

type Result

type Result struct {
	Headers          []Header `json:"headers"`
	HeaderCount      int      `json:"header_count"`
	DynamicTableSize int      `json:"dynamic_table_final_size"`
	BytesConsumed    int      `json:"bytes_consumed"`
	Notes            []string `json:"notes,omitempty"`
}

Result is the top-level decoded view.

func Decode

func Decode(hexStr string) (*Result, error)

Decode parses an HPACK-encoded header block from hex and returns the decoded headers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL