← Lessons

quiz vs the machine

Platinum1820

Networking

HTTP2 Header Compression with HPACK

Shrinking repetitive headers with tables and Huffman coding.

6 min read · advanced · beat Platinum to climb

Headers Repeat Themselves

Across many requests the same headers recur, like Host and User Agent. Sending them in full each time wastes bytes. HPACK is the header compression used by HTTP version two to remove this redundancy.

Two Tables

HPACK references headers by index into tables instead of resending their text.

  • The static table holds common header fields fixed by the specification.
  • The dynamic table grows as a connection runs, adding headers both sides have seen.

A header already in a table is sent as a small index. A new header may be added to the dynamic table for later reuse.

Huffman Coding

Literal values that are not in a table can be Huffman coded, a variable length encoding that shrinks common characters. Together, indexing and Huffman coding cut header size dramatically.

Why Not Generic Compression

Earlier attempts reused general stream compression for headers and were broken by an attack that recovered secrets from compressed sizes. HPACK was designed to resist this by limiting how attacker controlled and secret data mix.

Key idea

HPACK compresses HTTP version two headers by indexing into a static and a dynamic table and Huffman coding literals, a design that resists the compression side channel attacks that broke generic header compression.

Check yourself

Answer to earn rating on the learn ladder.

1. How does HPACK avoid resending a repeated header in full?

2. What is the dynamic table used for?

3. Why was a purpose built scheme chosen over generic compression?