<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.9 -->
<?rfc toc="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc docmapping="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     docName="draft-ietf-quic-qcram-latest"
     ipr="trust200902"
     submissionType="IETF">
   <x:feedback template="mailto:quic@ietf.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title abbrev="QCRAM">Header Compression for HTTP over QUIC</title>
      <author fullname="Charles 'Buck' Krasic" initials="C." surname="Krasic">
         <organization>Google, Inc</organization>
         <address>
            <email>ckrasic@google.com</email>
         </address>
      </author>
      <author fullname="Mike Bishop" initials="M." surname="Bishop">
         <organization>Akamai Technologies</organization>
         <address>
            <email>mbishop@evequefou.be</email>
         </address>
      </author>
      <author fullname="Alan Frindell"
              initials="A."
              role="editor"
              surname="Frindell">
         <organization>Facebook</organization>
         <address>
            <email>afrind@fb.com</email>
         </address>
      </author>
      <date/>
      <area>Transport</area>
      <workgroup>QUIC</workgroup>
      <abstract>
         <t>This specification defines QCRAM, a compression format for efficiently representing HTTP header fields, to be used in HTTP over QUIC. This is a variation of HPACK header compression that seeks to reduce head-of-line blocking.</t>
      </abstract>
      <note title="Note to Readers">
         <t>Discussion of this draft takes place on the QUIC working group mailing list (quic@ietf.org), which is archived at <eref target="https://mailarchive.ietf.org/arch/search/?email_list=quic">https://mailarchive.ietf.org/arch/search/?email_list=quic</eref>.</t>
         <t>Working Group information can be found at <eref target="https://github.com/quicwg">https://github.com/quicwg</eref>; source code and issues list for this draft can be found at <eref target="https://github.com/quicwg/base-drafts/labels/-qcram">https://github.com/quicwg/base-drafts/labels/-qcram</eref>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>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 <xref target="hol-example"/>).</t>
         <t>QUIC is described in <xref target="QUIC-TRANSPORT"/>. The HTTP/QUIC mapping is described in <xref target="QUIC-HTTP"/>. For a full description of HTTP/2, see <xref target="RFC7540"/>. The description of HPACK is <xref target="RFC7541"/>, with important terminology in Section 1.3.</t>
         <t>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.</t>
         <t>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.</t>
         <section anchor="hol-example" title="Head-of-Line Blocking in HPACK">
            <t>HPACK enables several types of header representations, one of which also adds the header to a dynamic table of header values. These values are then available for reuse in subsequent header blocks simply by referencing the entry number in the table.</t>
            <t>If the packet containing a header is lost, that stream cannot complete header processing until the packet is retransmitted. This is unavoidable. However, other streams which rely on the state created by that packet <spanx>also</spanx> cannot make progress. This is the problem which QUIC solves in general, but which is reintroduced by HPACK when the loss includes a HEADERS frame.</t>
         </section>
         <section anchor="overview-hol-avoidance"
                  title="Avoiding Head-of-Line Blocking in HTTP/QUIC">
            <t>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.</t>
            <t>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 <xref target="QUIC-HTTP"/>).</t>
            <t>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 <xref target="RFC7541" x:fmt="of" x:sec="6.2"/>).</t>
            <t>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.</t>
            <t>The header block contains a prefix (<xref target="absolute-index"/>). This prefix contains table offset information that establishes total ordering among all headers, regardless of reordering in the transport (see <xref target="overview-absolute"/>).</t>
            <t>In blocking mode, the prefix additionally identifies the minimum state required to process any vulnerable references in the header block (see <spanx style="verb">Depends Index</spanx> in <xref target="overview-absolute"/>). 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 <spanx style="verb">[1, Depends Index]</spanx> have been added. While blocked, header field data MUST remain in the blocked stream’s flow control window.</t>
         </section>
      </section>
      <section anchor="hpack-extensions" title="HPACK extensions">
         <section anchor="allowed-instructions" title="Allowed Instructions">
            <t>HEADERS frames on the Control Stream SHOULD contain only Literal with Incremental Indexing and Indexed with Duplication (see <xref target="indexed-duplicate"/>) representations. Frames on this stream modify the dynamic table state without generating output to any particular request.</t>
            <t>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.</t>
         </section>
         <section anchor="absolute-index" title="Header Block Prefix">
            <t>For request and push promise streams, in HEADERS and PUSH_PROMISE frames, HPACK Header data is prefixed by an integer: <spanx style="verb">Base Index</spanx>. <spanx style="verb">Base index</spanx> is the cumulative number of entries added to the dynamic table prior to encoding the current block, including any entries already evicted. It is encoded as a single 8-bit prefix integer:</t>
            <figure anchor="fig-base-index" title="Absolute indexing (BLOCKING=0x0)">
               <artwork type="drawing">
    0 1 2 3 4 5 6 7
   +-+-+-+-+-+-+-+-+
   |Base Index (8+)|
   +---------------+
</artwork>
            </figure>
            <t>
               <xref target="overview-absolute"/> describes the role of <spanx style="verb">Base Index</spanx>.</t>
            <t>When the BLOCKING flag is 0x1, a the prefix additionally contains a second HPACK integer (8-bit prefix) ‘Depends’:</t>
            <figure anchor="fig-prefix-long" title="Absolute indexing (BLOCKING=0x1)">
               <artwork type="drawing">
    0 1 2 3 4 5 6 7
   +-+-+-+-+-+-+-+-+
   |Base Index (8+)|
   +---------------+
   |Depends    (8+)|
   +---------------+
</artwork>
            </figure>
            <t>Depends is used to identify header dependencies (see <xref target="overview-hol-avoidance"/>). The encoder computes a value <spanx style="verb">Depends Index</spanx> which is the largest (absolute) index referenced by the following header block. To help keep the prefix smaller, <spanx style="verb">Depends Index</spanx> is converted to a relative value: <spanx style="verb">Depends = Base Index - Depends Index</spanx>.</t>
         </section>
         <section anchor="overview-absolute" title="Hybrid absolute-relative indexing">
            <t>HPACK indexed entries refer to an entry by its current position in the dynamic table. As Figure 1 of <xref target="RFC7541"/> 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.</t>
            <t>QCRAM uses a hybrid absolute-relative indexing approach.</t>
            <t>When the encoder adds a new entry to its header table, it can compute an absolute index:</t>
            <t>
               <spanx style="verb">entry.absoluteIndex = baseIndex++;</spanx>
            </t>
            <t>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.</t>
            <t>When encoding indexed representations, the following holds for (relative) HPACK indices:</t>
            <t>
               <spanx style="verb">relative index = baseIndex - entry.absoluteIndex + staticTable.size</spanx>
            </t>
            <t>Header blocks on request and push streams do not modify the dynamic table state, so they never change the <spanx style="verb">baseIndex</spanx>. However, since ordering between streams is not guaranteed, the value of <spanx style="verb">baseIndex</spanx> can not be synchronized implicitly. Instead then, QCRAM sends encoder’s <spanx style="verb">Base Index</spanx> explicitly as part of the prefix (see <xref target="absolute-index"/>), so that the decoder can compute the same absolute indices that the encoder used:</t>
            <t>
               <spanx style="verb">absoluteIndex = prefix.baseIndex + staticTable.size - relativeIndex;</spanx>
            </t>
            <t>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.</t>
            <t>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 <spanx style="verb">HTTP_HPACK_DECOMPRESSION_FAILED</spanx> error code.</t>
         </section>
         <section anchor="evictions" title="Preventing Eviction Races">
            <t>Due to out-of-order arrival, QCRAM’s eviction algorithm requires changes (relative to HPACK) to avoid the possibility that an indexed representation is decoded after the referenced entry has already been evicted. QCRAM employs a two-phase eviction algorithm, in which the encoder will not evict entries that have outstanding (unacknowledged) references.</t>
            <section anchor="blocked-evictions" title="Blocked Evictions">
               <t>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.</t>
               <t>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.</t>
               <t>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 <xref target="indexed-duplicate"/>).</t>
            </section>
         </section>
         <section anchor="indexed-duplicate" title="Refreshing Entries with Duplication">
            <figure anchor="fig-index-with-duplication"
                    title="Indexed Header Field with Duplication">
               <artwork type="drawing">
    0 1 2 3 4 5 6 7
   +-+-+-+-+-+-+-+-+
   |0|0|1|Index(5+)|
   +-+-+-+---------+
</artwork>
            </figure>
            <t>
               <spanx>Indexed-Duplicates</spanx> insert a new entry into the dynamic table which duplicates an existing entry. <xref target="RFC7541"/> allows duplicate HPACK table entries, that is entries that have the same name and value.</t>
            <t>This replaces the HPACK instruction for Dynamic Table Size Update (see <xref target="RFC7541" x:fmt="of" x:sec="6.3"/>, which is not supported by HTTP over QUIC.</t>
         </section>
      </section>
      <section anchor="performance-considerations" title="Performance considerations">
         <section anchor="speculative-updates" title="Speculative table updates">
            <t>Implementations can <spanx>speculatively</spanx> 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 <spanx>refresh</spanx> by sending Indexed-Duplicate representations for popular header fields (<xref target="absolute-index"/>), ensuring they have small indices and hence minimal size on the wire.</t>
         </section>
         <section anchor="additional-state-beyond-hpack"
                  title="Additional state beyond HPACK.">
            <section anchor="vulnerable-entries" title="Vulnerable Entries">
               <t>For header blocks encoded in non-blocking mode, the encoder needs to forego indexed representations that refer to vulnerable entries (see <xref target="overview-hol-avoidance"/>). An implementation could extend the header table entry with a boolean to track vulnerability. However, the number of entries in the table that are vulnerable is likely to be small in practice, much less than the total number of entries, so a data tracking only vulnerable (un-acknowledged) entries, separate from the main header table, might be more space efficient.</t>
            </section>
            <section anchor="safe-evictions" title="Safe evictions">
               <t>Section <xref target="evictions"/> describes how QCRAM avoids invalid references that might result from out-of-order delivery. When the encoder processes a HEADER_ACK, it dereferences table entries that were indexed in the acknowledged header. To track which entries must be dereferenced, it can maintain a map from unacknowledged headers to lists of (absolute) indices. The simplest place to store the actual reference count might be the table entries. In practice the number of entries in the table with a non-zero reference count is likely to stay quite small. A data structure tracking only entries with non-zero reference counts, separate from the main header table, could be more space efficient.</t>
            </section>
            <section anchor="decoder-blocking" title="Decoder Blocking">
               <t>To support blocking, the decoder needs to keep track of entries it has added to the dynamic table (see <xref target="overview-hol-avoidance"/>), and it needs to track blocked streams.</t>
               <t>Tracking added entries might be done in a brute force fashion without additional space. However, this would have O(N) cost where N is the number of entries in the dynamic table. Alternatively, a dedicated data structure might improve on brute force in exchange a small amount of additional space. For example, a set of pairs (of indices), representing non-overlapping sub-ranges can be used. Each operation (add, or query) can be done within O(log M) complexity. Here set size M is the number of sub-ranges. In practice M would be very small, as most table entries would be concentrated in the first sub-range <spanx style="verb">[1,M]</spanx>.</t>
               <t>To track blocked streams, an ordered map (e.g. multi-map) from <spanx style="verb">Depends Index</spanx> values to streams can be used. Whenever the decoder processes a header block, it can drain any members of the blocked streams map that have <spanx style="verb">Depends Index &lt;= M</spanx> where <spanx style="verb">[1,M]</spanx> is the first member of the added- entries sub-ranges set. Again, the complexity of operations would be at most O(log N), N being the number of concurrently blocked streams.</t>
            </section>
            <section anchor="fixed-overhead" title="Fixed overhead.">
               <t>HPACK defines overhead as 32 bytes (<xref target="RFC7541" x:fmt="," x:sec="4.1"/>). As described above, QCRAM adds some per-connection state, and possibly some per-entry state to track acknowledgment status and eviction reference count. A larger value than 32 might be more accurate for QCRAM.</t>
            </section>
         </section>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>TBD.</t>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <t>This document registers a new frame type, HEADER_ACK, for HTTP/QUIC. This will need to be added to the IANA Considerations of <xref target="QUIC-HTTP"/>.</t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="QUIC-HTTP">
            <front>
               <title>Hypertext Transfer Protocol Version 3 (HTTP/3)</title>
               <author fullname="Mike Bishop" initials="M" surname="Bishop"/>
               <date day="23" month="April" year="2019"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-http-20"/>
         </reference>
         <reference anchor="RFC7541">
            <front>
               <title>HPACK: Header Compression for HTTP/2</title>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="H. Ruellan" initials="H." surname="Ruellan"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7541"/>
            <seriesInfo name="DOI" value="10.17487/RFC7541"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="QUIC-TRANSPORT">
            <front>
               <title>QUIC: A UDP-Based Multiplexed and Secure Transport</title>
               <author fullname="Jana Iyengar" initials="J" surname="Iyengar"/>
               <author fullname="Martin Thomson" initials="M" surname="Thomson"/>
               <date day="23" month="April" year="2019"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-transport-20"/>
         </reference>
         <reference anchor="RFC7540">
            <front>
               <title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
               <author fullname="M. Belshe" initials="M." surname="Belshe"/>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="M. Thomson"
                       initials="M."
                       role="editor"
                       surname="Thomson"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7540"/>
            <seriesInfo name="DOI" value="10.17487/RFC7540"/>
         </reference>
      </references>
      <section anchor="acknowledgments" numbered="false" title="Acknowledgments">
         <t>This draft draws heavily on the text of <xref target="RFC7541"/>. The indirect input of those authors is gratefully acknowledged, as well as ideas from:</t>
         <t>
            <list style="symbols">
               <t>Ryan Hamilton</t>
               <t>Patrick McManus</t>
               <t>Kazuho Oku</t>
               <t>Biren Roy</t>
               <t>Ian Swett</t>
               <t>Dmitri Tikhonov</t>
            </list>
         </t>
      </section>
   </back>
</rfc>
