Search code examples
http2

How does headers keep sync in both client and server side in HTTP/2?


As HTTP/2 use hpack to compress headers, it has a static table and a dynamic table per connection. But I got a question, how does client & server side sync headers?


Solution

  • There are two tables: one for the client-initiated messages and one for server-initiated messages.

    As per the spec:

    When used for bidirectional communication, such as in HTTP, the encoding and decoding dynamic tables maintained by an endpoint are completely independent, i.e., the request and response dynamic tables are separate.

    Both client and server must manage copies of both tables. So when a client sends a message it updates it’s copy of the client table, and when the client receives a message, the client updates it’s copy of the server table. And similarly on the server side.

    As TCP guarantees the delivery order of messages it’s possible to keep the client table in sync on the client and server side (and similarly with the server table side). This would be more complicated on a connection where in-order messaging is not guaranteed so QUIC uses a variety on HPACK called QPACK which has extra features to handle this.