Header Compression for HTTP over QUIC Google, Inc
Akamai Technologies
Transport QUIC The design of the core QUIC transport subsumes many HTTP/2 features, prominent among them stream multiplexing. A key advantage of the QUIC transport is stream multiplexing free of head-of-line (HoL) blocking between streams. In HTTP/2, multiplexed streams can suffer HoL blocking due to TCP. If HTTP/2’s HPACK is used for header compression, HTTP/QUIC is still vulnerable to HoL blocking, because of HPACK’s assumption of in-order delivery. This draft defines QCRAM, a variation of HPACK and mechanisms in the HTTP/QUIC mapping that allow the flexibility to avoid header-compression-induced HoL blocking.
The QUIC transport protocol was designed from the outset to support HTTP semantics, and its design subsumes many of the features of HTTP/2. QUIC’s stream multiplexing comes into some conflict with header compression. A key goal of the design of QUIC is to improve stream multiplexing relative to HTTP/2 by eliminating HoL (head of line) blocking, which can occur in HTTP/2. HoL blocking can happen because all HTTP/2 streams are multiplexed onto a single TCP connection with its in-order semantics. QUIC can maintain independence between streams because it implements core transport functionality in a fully stream-aware manner. However, the HTTP/QUIC mapping is still subject to HoL blocking if HPACK is used directly. HPACK exploits multiplexing for greater compression, shrinking the representation of headers that have appeared earlier on the same connection. In the context of QUIC, this imposes a vulnerability to HoL blocking (see ). QUIC is described in . The HTTP/QUIC mapping is described in . For a full description of HTTP/2, see . The description of HPACK is , with important terminology in Section 1.3. QCRAM modifies HPACK to allow correctness in the presence of out-of-order delivery, with flexibility for implementations to balance between resilience against HoL blocking and optimal compression ratio. The design goals are to closely approach the compression ratio of HPACK with substantially less head-of-line blocking under the same loss conditions. QCRAM is intended to be a relatively non-intrusive extension to HPACK; an implementation should be easily shared within stacks supporting both HTTP/2 over (TLS+)TCP and HTTP/QUIC.
In the example above, the second stream contained a reference to data which might not yet have been processed by the recipient. Such references are called “vulnerable,” because the loss of a different packet can keep the reference from being usable. The encoder can choose on a per-header-block basis whether to favor higher compression ratio (by permitting vulnerable references) or HoL resilience (by avoiding them). This is signaled by the BLOCKING flag in HEADERS and PUSH_PROMISE frames (see ). If a header block contains no vulnerable header fields, BLOCKING MUST be 0. This implies that the header fields are represented either as references to dynamic table entries which are known to have been received, or as Literal header fields (see ). If a header block contains any header field which references dynamic table state which the peer might not have received yet, the BLOCKING flag MUST be set. If the peer does not yet have the appropriate state, such blocks might not be processed on arrival. The header block contains a prefix (). This prefix contains table offset information that establishes total ordering among all headers, regardless of reordering in the transport (see ). In blocking mode, the prefix additionally identifies the minimum state required to process any vulnerable references in the header block (see Depends Index in ). The decoder keeps track of which entries have been added to its dynamic table. The stream for a header with BLOCKING flag set is considered blocked by the decoder and can not be processed until all entries in the range [1, Depends Index] have been added. While blocked, header field data MUST remain in the blocked stream’s flow control window.
HEADERS and PUSH_PROMISE frames define a new flag. Indicates the stream might need to wait for dependent headers before processing. If 0, the frame can be processed immediately upon receipt. HEADERS frames can be sent on the Connection Control Stream as well as on request / push streams. The value of BLOCKING MUST be 0 for HEADERS frames on the Connection Control Stream, since they can only depend on previous HEADERS on the same stream.
The HEADER_ACK frame (type=0x8) is sent from the decoder to the encoder on the Control Stream when the decoder has fully processed a header block. It is used by the encoder to determine whether subsequent indexed representations that might reference that block are vulnerable to HoL blocking, and to prevent eviction races (see ). The HEADER_ACK frame indicates the stream on which the header block was processed by encoding the Stream ID as a variable-length integer. The same Stream ID can be identified multiple times, as multiple header-containing blocks can be sent on a single stream in the case of intermediate responses, trailers, pushed requests, etc. as well as on the Control Streams. Since header frames on each stream are received and processed in order, this gives the encoder precise feedback on which header blocks within a stream have been fully processed.
0 1 2 3 4 5 6 7 +---+---+---+---+---+---+---+---+ | Stream ID [i] | +---+---------------------------+
The HEADER_ACK frame does not define any flags.
HEADERS frames on the Control Stream SHOULD contain only Literal with Incremental Indexing and Indexed with Duplication (see ) representations. Frames on this stream modify the dynamic table state without generating output to any particular request. HEADERS and PUSH_PROMISE frames on request and push streams MUST NOT contain Literal with Incremental Indexing and Indexed with Duplication representations. Frames on these streams reference the dynamic table in a particular state without modifying it, but emit the headers for an HTTP request or response.
0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |Base Index (8+)| +---------------+
describes the role of Base Index. When the BLOCKING flag is 0x1, a the prefix additionally contains a second HPACK integer (8-bit prefix) ‘Depends’:
0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |Base Index (8+)| +---------------+ |Depends (8+)| +---------------+
Depends is used to identify header dependencies (see ). The encoder computes a value Depends Index which is the largest (absolute) index referenced by the following header block. To help keep the prefix smaller, Depends Index is converted to a relative value: Depends = Base Index - Depends Index.
HPACK indexed entries refer to an entry by its current position in the dynamic table. As Figure 1 of illustrates, newer entries have smaller indices, and older entries are evicted first if the table is full. Under this scheme, each insertion to the table causes the index of all existing entries to change (implicitly). Implicit index updates are acceptable for HTTP/2 because TCP is totally ordered, but are problematic in the out-of-order context of QUIC. QCRAM uses a hybrid absolute-relative indexing approach. When the encoder adds a new entry to its header table, it can compute an absolute index: entry.absoluteIndex = baseIndex++; Since literals with indexing are only sent on the control stream, the decoder can be guaranteed to compute the same absolute index values when it adds corresponding entries to its table, just as in HPACK and HTTP/2. When encoding indexed representations, the following holds for (relative) HPACK indices: relative index = baseIndex - entry.absoluteIndex + staticTable.size Header blocks on request and push streams do not modify the dynamic table state, so they never change the baseIndex. However, since ordering between streams is not guaranteed, the value of baseIndex can not be synchronized implicitly. Instead then, QCRAM sends encoder’s Base Index explicitly as part of the prefix (see ), so that the decoder can compute the same absolute indices that the encoder used: absoluteIndex = prefix.baseIndex + staticTable.size - relativeIndex; In this way, even if request or push stream headers are decoded in a different order than encoded, the absolute indices will still identify the correct table entries. It is an error if the HPACK decoder encounters an indexed representation that refers to an entry missing from the table, and the connection MUST be closed with the HTTP_HPACK_DECOMPRESSION_FAILED error code.
The encoder MUST NOT permit an entry to be evicted while a reference to that entry remains unacknowledged. If a new header to be inserted into the dynamic table would cause the eviction of such an entry, the encoder MUST NOT emit the insert instruction until the reference has been processed by the decoder and acknowledged. The encoder can emit a literal representation for the new header in order to avoid encoding delays, and MAY insert the header into the table later if desired. To ensure that the blocked eviction case is rare, references to the oldest entries in the dynamic table SHOULD be avoided. When one of the oldest entries in the table is still actively used for references, the encoder SHOULD emit an Indexed-Duplicate representation instead (see ).
0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |0|0|1|Index(5+)| +-+-+-+---------+
Indexed-Duplicates insert a new entry into the dynamic table which duplicates an existing entry. allows duplicate HPACK table entries, that is entries that have the same name and value. This replaces the HPACK instruction for Dynamic Table Size Update (see , which is not supported by HTTP over QUIC.
Implementations can speculatively send header frames on the HTTP Control Streams which are not needed for any current HTTP request or response. Such headers could be used strategically to improve performance. For instance, the encoder might decide to refresh by sending Indexed-Duplicate representations for popular header fields (), ensuring they have small indices and hence minimal size on the wire.
This draft draws heavily on the text of . The indirect input of those authors is gratefully acknowledged, as well as ideas from: Mike Bishop Alan Frindell Ryan Hamilton Patrick McManus Kazuho Oku Biren Roy Ian Swett Dmitri Tikhonov
Hypertext Transfer Protocol (HTTP) over QUIC HPACK: Header Compression for HTTP/2 QUIC: A UDP-Based Multiplexed and Secure Transport Hypertext Transfer Protocol Version 2 (HTTP/2)