Chapter 8. HPACK header compression


This chapter covers

  • Background on data compression
  • Why HTTP/2 needed its own compression technique for HTTP headers
  • The HPACK compression format
  • Decompressing HPACK encoded headers
  • HPACK in client and server implementations

The next topic is header compression. HTTP/1 has always allowed HTTP bodies to be compressed, but only since HTTP/2 has it been possible to compress the HTTP headers too.

8.1. Why is header compression needed?

It’s true that, in general, HTTP headers are relatively small in comparison with HTTP bodies, but they’re still chatty and repetitive. A typical HTTP/2 GET request from Chrome looks like this:

:method: GET
:path: /url
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,
accept-encoding: gzip, deflate, br
accept-language: en-GB,en-US;q=0.9,en;q=0.8
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537
.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36

{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":9},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":7},{\"line\":2,\"ch\":11}]]"}

8.2. How compression works

8.3. HTTP body compression

8.4. HPACK header compression for HTTP/2

8.5. Real-world examples of HPACK compression

8.6. HPACK in client and server implementations

8.7. The value of HPACK