<?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.7 -->
<?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-qpack-00"
     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="QPACK">QPACK: 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 year="2018" month="May" day="23"/>
      <area>Transport</area>
      <workgroup>QUIC</workgroup>
      <abstract>
         <t>This specification defines QPACK, 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/-qpack">https://github.com/quicwg/base-drafts/labels/-qpack</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>QPACK 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>QPACK 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>Because QUIC does not guarantee order between data on different streams, a header block might reference an entry in the dynamic table that has not yet been received.</t>
            <t>Each header block contains a Largest Reference (see <xref target="absolute-index"/>) which identifies the table state necessary for decoding. If the greatest absolute index in the dynamic table is less than the value of the Largest Reference, the stream is considered “blocked.” While blocked, header field data should remain in the blocked stream’s flow control window. When the Largest Reference is zero, the frame contains no references to the dynamic table and can always be processed immediately. A stream becomes unblocked when the greatest absolute index in the dynamic table becomes greater than or equal to the Largest Reference for all header blocks the decoder has started reading from the stream.</t>
            <t>A decoder can permit the possibility of blocked streams by setting SETTINGS_QPACK_BLOCKED_STREAMS to a non-zero value. This setting specifies an upper bound on the number of streams which can be blocked.</t>
            <t>An encoder can decide whether to risk having a stream become blocked. If permitted by the value of SETTINGS_QPACK_BLOCKED_STREAMS, compression efficiency can be improved by referencing dynamic table entries that are still in transit, but if there is loss or reordering the stream can become blocked at the decoder. An encoder avoids the risk of blocking by only referencing dynamic table entries which have been acknowledged, but this means using literals. Since literals make the header block larger, this can result in the encoder becoming blocked on congestion or flow control limits.</t>
            <t>An encoder MUST limit the number of streams which could become blocked to the value of SETTINGS_QPACK_BLOCKED_STREAMS at all times. Note that the decoder might not actually become blocked on every stream which risks becoming blocked. If the decoder encounters more blocked streams than it promised to support, it SHOULD treat this as a stream error of type HTTP_QPACK_DECOMPRESSION_FAILED.</t>
         </section>
      </section>
      <section anchor="conventions-and-definitions"
               title="Conventions and Definitions">
         <t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/>
            <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
         <t>Definitions of terms that are used in this document:</t>
         <t>
            <list style="hanging">
               <t hangText="Header:">A name-value pair sent as part of an HTTP message.</t>
               <t hangText="Header set:">The full collection of headers associated with an HTTP message.</t>
               <t hangText="Header block:">The compressed representation of a header set.</t>
               <t hangText="Encoder:">An implementation which transforms a header set into a header block.</t>
               <t hangText="Decoder:">An implementation which transforms a header block into a header set.</t>
            </list>
         </t>
         <t>QPACK is a name, not an acronym.</t>
         <section anchor="notational-conventions" title="Notational Conventions">
            <t>Diagrams use the format described in <xref target="RFC2360" x:fmt="of" x:sec="3.1"/>, with the following additional conventions:</t>
            <t>
               <list style="hanging">
                  <t hangText="x (A)">Indicates that x is A bits long</t>
                  <t hangText="x (A+)">Indicates that x uses the prefixed integer encoding defined in <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>, beginning with an A-bit prefix.</t>
                  <t hangText="x …">Indicates that x is variable-length and extends to the end of the region.</t>
               </list>
            </t>
         </section>
      </section>
      <section anchor="wire-format" title="Wire Format">
         <t>QPACK instructions occur in three locations, each of which uses a separate instruction space:</t>
         <t>
            <list style="symbols">
               <t>Table updates are carried by a unidirectional stream from encoder to decoder. Instructions on this stream modify the dynamic table state without generating output to any particular request.</t>
               <t>Acknowledgements of table modifications and header processing are carried by a unidirectional stream from decoder to encoder.</t>
               <t>Finally, the contents of HEADERS and PUSH_PROMISE frames on request streams reference the QPACK table state.</t>
            </list>
         </t>
         <t>This section describes the instructions which are possible on each stream type.</t>
         <t>All table updates occur on the control stream. Request streams only carry header blocks that do not modify the state of the table.</t>
         <section anchor="primitives" title="Primitives">
            <t>The prefixed integer from <xref target="RFC7541" x:fmt="of" x:sec="5.1"/> is used heavily throughout this document. The string literal, defined by <xref target="RFC7541" x:fmt="of" x:sec="5.2"/>, is used with the following modification.</t>
            <t>HPACK defines string literals to begin on a byte boundary. They begin with a single flag (indicating whether the string is Huffman-coded), followed by the Length encoded as a 7-bit prefix integer, and finally Length octets of data.</t>
            <t>QPACK permits strings to begin other than on a byte boundary. An “N-bit prefix string literal” begins with the same Huffman flag, followed by the length encoded as an (N-1)-bit prefix integer. The remainder of the string literal is unmodified.</t>
            <t>A string literal without a prefix length noted is an 8-bit prefix string literal and follows the definitions in <xref target="RFC7541"/> without modification.</t>
         </section>
         <section anchor="indexing" title="Indexing">
            <t>Entries in the QPACK static and dynamic tables are addressed separately.</t>
            <t>Entries in the static table have the same indices at all times. The static table is defined in <xref target="RFC7541" x:fmt="of" x:sec="A"/>. Note that because HPACK did not use zero-based references, there is no value at index zero of the static table.</t>
            <t>Entries are inserted into the dynamic table over time. Each entry possesses both an absolute index which is fixed for the lifetime of that entry and a relative index which changes over time based on the context of the reference. The first entry inserted has an absolute index of “1”; indices increase sequentially with each insertion.</t>
            <t>On the control stream, a relative index of “0” always refers to the most recently inserted value in the dynamic table. Note that this means the entry referenced by a given relative index can change while interpreting a HEADERS frame as new entries are inserted.</t>
            <figure title="Example Dynamic Table Indexing - Control Stream">
               <artwork type="drawing">
    +---+---------------+-------+
    | n |      ...      | d + 1 |  Absolute Index
    + - +---------------+   -   +
    | 0 |      ...      | n-d-1 |  Relative Index
    +---+---------------+-------+
      ^                     |
      |                     V
Insertion Point         Dropping Point

n = count of entries inserted
d = count of entries dropped
</artwork>
            </figure>
            <t>Because frames from request streams can be delivered out of order with instructions on the control stream, relative indices are relative to the Base Index at the beginning of the header block (see <xref target="absolute-index"/>). The Base Index is the absolute index of the entry which has the relative index of zero when interpreting the frame. The relative indices of entries do not change while interpreting headers on a request or push stream.</t>
            <figure title="Example Dynamic Table Indexing - Request Stream">
               <artwork type="drawing">
             Base Index
                 |
                 V
    +---+-----+-----+-----+-------+
    | n | n-1 | n-2 | ... |  d+1  |  Absolute Index
    +---+-----+  -  +-----+   -   +
              |  0  | ... | n-d-3 |  Relative Index
              +-----+-----+-------+

n = count of entries inserted
d = count of entries dropped
</artwork>
            </figure>
            <t>Entries with an absolute index greater than a frame’s Base Index can be referenced using specific Post-Base instructions. The relative indices of Post-Base references count up from Base Index.</t>
            <figure title="Dynamic Table Indexing - Post-Base References">
               <artwork type="drawing">
             Base Index
                 |
                 V
    +---+-----+-----+-----+-----+
    | n | n-1 | n-2 | ... | d+1 |  Absolute Index
    +---+-----+-----+-----+-----+
    | 1 |  0  |                    Post-Base Index
    +---+-----+

n = count of entries inserted
d = count of entries dropped
</artwork>
            </figure>
            <t>If the decoder encounters a reference to an entry which has already been dropped from the table or which is greater than the declared Largest Reference, this MUST be treated as a stream error of type <spanx style="verb">HTTP_QPACK_DECOMPRESSION_FAILED</spanx> error code. If this reference occurs on the control stream, this MUST be treated as a session error.</t>
         </section>
         <section anchor="qpack-encoder-stream" title="QPACK Encoder Stream">
            <t>Table updates can add a table entry, possibly using existing entries to avoid transmitting redundant information. The name can be transmitted as a reference to an existing entry in the static or the dynamic table or as a string literal. For entries which already exist in the dynamic table, the full entry can also be used by reference, creating a duplicate entry.</t>
            <t>Each set of encoder instructions is prefaced by its length, encoded as a variable length integer with an 8-bit prefix. Instructions MUST NOT span more than one block.</t>
            <figure title="Encoder instruction block">
               <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   |       Block Length (8+)       |
   +-------------------------------+
   |     Instruction Block (*)   ...
   +-------------------------------+
</artwork>
            </figure>
            <section anchor="insert-with-name-reference" title="Insert With Name Reference">
               <t>An addition to the header table where the header field name matches the header field name of an entry stored in the static table or the dynamic table starts with the ‘1’ one-bit pattern. The <spanx style="verb">S</spanx> bit indicates whether the reference is to the static (S=1) or dynamic (S=0) table. The header field name is represented using the relative index of that entry, which is represented as an integer with a 6-bit prefix (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>).</t>
               <t>The header name reference is followed by the header field value represented as a string literal (see <xref target="RFC7541" x:fmt="of" x:sec="5.2"/>).</t>
               <figure title="Insert Header Field -- Indexed Name">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 1 | S |    Name Index (6+)    |
   +---+---+-----------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   | Value String (Length octets)  |
   +-------------------------------+
</artwork>
               </figure>
            </section>
            <section anchor="insert-without-name-reference"
                     title="Insert Without Name Reference">
               <t>An addition to the header table where both the header field name and the header field value are represented as string literals (see <xref target="primitives"/>) starts with the ‘01’ two-bit pattern.</t>
               <t>The name is represented as a 6-bit prefix string literal, while the value is represented as an 8-bit prefix string literal.</t>
               <figure title="Insert Header Field -- New Name">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 | H | Name Length (5+)  |
   +---+---+---+-------------------+
   |  Name String (Length octets)  |
   +---+---------------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   | Value String (Length octets)  |
   +-------------------------------+
</artwork>
               </figure>
            </section>
            <section anchor="duplicate" title="Duplicate">
               <t>Duplication of an existing entry in the dynamic table starts with the ‘000’ three-bit pattern. The relative index of the existing entry is represented as an integer with a 5-bit prefix.</t>
               <figure anchor="fig-index-with-duplication" title="Duplicate">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | 0 |    Index (5+)     |
   +---+---+---+-------------------+
</artwork>
               </figure>
               <t>The existing entry is re-inserted into the dynamic table without resending either the name or the value. This is useful to mitigate the eviction of older entries which are frequently referenced, both to avoid the need to resend the header and to avoid the entry in the table blocking the ability to insert new headers.</t>
            </section>
            <section anchor="dynamic-table-size-update" title="Dynamic Table Size Update">
               <t>An encoder informs the decoder of a change to the size of the dynamic table using an instruction which begins with the ‘001’ three-bit pattern. The new maximum table size is represented as an integer with a 5-bit prefix (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>).</t>
               <figure anchor="fig-size-change" title="Maximum Dynamic Table Size Change">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 |   Max size (5+)   |
+---+---+---+-------------------+
</artwork>
               </figure>
               <t>The new maximum size MUST be lower than or equal to the limit determined by the protocol using QPACK. A value that exceeds this limit MUST be treated as a decoding error. In HTTP/QUIC, this limit is the value of the SETTINGS_HEADER_TABLE_SIZE parameter (see <xref target="QUIC-HTTP"/>) received from the decoder.</t>
               <t>Reducing the maximum size of the dynamic table can cause entries to be evicted (see <xref target="RFC7541" x:fmt="of" x:sec="4.3"/>). This MUST NOT cause the eviction of entries with outstanding references (see <xref target="reference-tracking"/>).</t>
            </section>
         </section>
         <section anchor="feedback" title="QPACK Decoder Stream">
            <t>The decoder stream carries information used to ensure consistency of the dynamic table. Information is sent from the QPACK decoder to the QPACK encoder; that is, the server informs the client about the processing of the client’s header blocks and table updates, and the client informs the server about the processing of the server’s header blocks and table updates.</t>
            <section anchor="table-state-synchronize" title="Table State Synchronize">
               <t>After processing a set of instructions on the encoder stream, the decoder will emit a Table State Synchronize instruction on the decoder stream. The instruction begins with the ‘1’ one-bit pattern. The instruction specifies the total number of dynamic table inserts and duplications since the last Table State Synchronize, encoded as a 7-bit prefix integer. The encoder uses this value to determine which table entries are vulnerable to head-of-line blocking. A decoder MAY coalesce multiple synchronization updates into a single update.</t>
               <figure anchor="fig-size-sync" title="Table Size Synchronize">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 1 |     Insert Count (7+)     |
+---+---------------------------+
</artwork>
               </figure>
            </section>
            <section anchor="header-acknowledgement" title="Header Acknowledgement">
               <t>After processing a header block on a request or push stream, the decoder emits a Header Acknowledgement instruction on the decoder stream. The instruction begins with the ‘0’ one-bit pattern and includes the request stream’s stream ID, encoded as a 7-bit prefix integer. It is used by the peer’s QPACK encoder to know when it is safe to evict an entry.</t>
               <t>The same Stream ID can be identified multiple times, as multiple header blocks can be sent on a single stream in the case of intermediate responses, trailers, and pushed requests. 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.</t>
               <figure anchor="fig-header-ack" title="Header Acknowledgement">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 |      Stream ID (7+)       |
+---+---------------------------+
</artwork>
               </figure>
            </section>
         </section>
         <section anchor="request-and-push-streams" title="Request and Push Streams">
            <t>HEADERS and PUSH_PROMISE frames on request and push streams reference the dynamic table in a particular state without modifying it. Frames on these streams emit the headers for an HTTP request or response.</t>
            <section anchor="absolute-index" title="Header Data Prefix">
               <t>Header data is prefixed with two integers, <spanx style="verb">Largest Reference</spanx> and <spanx style="verb">Base Index</spanx>.</t>
               <figure anchor="fig-base-index" title="Frame Payload">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
|     Largest Reference (8+)    |
+---+---------------------------+
| S |   Delta Base Index (7+)   |
+---+---------------------------+
|      Compressed Headers     ...
+-------------------------------+
</artwork>
               </figure>
               <t>
                  <spanx style="verb">Largest Reference</spanx> identifies the largest absolute dynamic index referenced in the block. Blocking decoders use the Largest Reference to determine when it is safe to process the rest of the block.</t>
               <t>
                  <spanx style="verb">Base Index</spanx> is used to resolve references in the dynamic table as described in <xref target="indexing"/>. To save space, Base Index is encoded relative to Largest Reference using a one-bit sign flag.</t>
               <figure>
                  <artwork>
baseIndex = largestReference + deltaBaseIndex
</artwork>
               </figure>
               <t>If the encoder inserted entries to the table while the encoding the block, Largest Reference will be greater than Base Index, so deltaBaseIndex will be negative and encoded with S=1. If the block did not reference the most recent entry in the table and did not insert any new entries, Largest Reference will be less than Base Index, so deltaBaseIndex will be positive and encoded with S=0. When Largest Reference and Base Index are equal, deltaBaseIndex is 0 and encoded with S=0.</t>
            </section>
            <section anchor="instructions" title="Instructions">
               <section anchor="indexed-header-field" title="Indexed Header Field">
                  <t>An indexed header field representation identifies an entry in either the static table or the dynamic table and causes that header field to be added to the decoded header list, as described in <xref target="RFC7541" x:fmt="of" x:sec="3.2"/>.</t>
                  <figure title="Indexed Header Field">
                     <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 1 | S |      Index (6+)       |
+---+---+-----------------------+
</artwork>
                  </figure>
                  <t>If the entry is in the static table, or in the dynamic table with an absolute index less than or equal to Base Index, this representation starts with the ‘1’ 1-bit pattern, followed by the <spanx style="verb">S</spanx> bit indicating whether the reference is into the static (S=1) or dynamic (S=0) table. Finally, the relative index of the matching header field is represented as an integer with a 6-bit prefix (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>).</t>
                  <figure title="Indexed Header Field">
                     <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 1 | 0 | 0 |  Index (4+)   |
+---+---+-----------------------+
</artwork>
                  </figure>
                  <t>If the entry is in the dynamic table with an absolute index greater than Base Index, the representation starts with the ‘0100’ 4-bit pattern, followed by the post-base index (see <xref target="indexing"/>) of the matching header field, represented as an integer with a 4-bit prefix (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>).</t>
               </section>
               <section anchor="literal-header-field-with-name-reference"
                        title="Literal Header Field With Name Reference">
                  <t>A literal header field with a name reference represents a header where the header field name matches the header field name of an entry stored in the static table or the dynamic table.</t>
                  <t>If the entry is in the static table, or in the dynamic table with an absolute index less than or equal to Base Index, this representation starts with the ‘00’ two-bit pattern. If the entry is in the dynamic table with an absolute index greater than Base Index, the representation starts with the ‘0101’ four-bit pattern.</t>
                  <t>The following bit, ‘N’, indicates whether an intermediary is permitted to add this header to the dynamic header table on subsequent hops. When the ‘N’ bit is set, the encoded header MUST always be encoded with a literal representation. In particular, when a peer sends a header field that it received represented as a literal header field with the ‘N’ bit set, it MUST use a literal representation to forward this header field. This bit is intended for protecting header field values that are not to be put at risk by compressing them (see <xref target="RFC7541" x:fmt="of" x:sec="7.1"/> for more details).</t>
                  <figure title="Literal Header Field With Name Reference">
                     <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | N | S |Name Index (4+)|
   +---+---+-----------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   | Value String (Length octets)  |
   +-------------------------------+
</artwork>
                  </figure>
                  <t>For entries in the static table or in the dynamic table with an absolute index less than or equal to Base Index, the header field name is represented using the relative index of that entry, which is represented as an integer with a 4-bit prefix (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>). The <spanx style="verb">S</spanx> bit indicates whether the reference is to the static (S=1) or dynamic (S=0) table.</t>
                  <figure title="Literal Header Field With Post-Base Name Reference">
                     <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 | 0 | 1 | N |NameIdx(3+)|
   +---+---+-----------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   | Value String (Length octets)  |
   +-------------------------------+
</artwork>
                  </figure>
                  <t>For entries in the dynamic table with an absolute index greater than Base Index, the header field name is represented using the post-base index of that entry (see <xref target="indexing"/>) encoded as an integer with a 3-bit prefix.</t>
               </section>
               <section anchor="literal-header-field-without-name-reference"
                        title="Literal Header Field Without Name Reference">
                  <t>An addition to the header table where both the header field name and the header field value are represented as string literals (see <xref target="primitives"/>) starts with the ‘011’ three-bit pattern.</t>
                  <t>The fourth bit, ‘N’, indicates whether an intermediary is permitted to add this header to the dynamic header table on subsequent hops. When the ‘N’ bit is set, the encoded header MUST always be encoded with a literal representation. In particular, when a peer sends a header field that it received represented as a literal header field with the ‘N’ bit set, it MUST use a literal representation to forward this header field. This bit is intended for protecting header field values that are not to be put at risk by compressing them (see <xref target="RFC7541" x:fmt="of" x:sec="7.1"/> for more details).</t>
                  <t>The name is represented as a 4-bit prefix string literal, while the value is represented as an 8-bit prefix string literal.</t>
                  <figure title="Literal Header Field Without Name Reference">
                     <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 | 1 | N | H |NameLen(3+)|
   +---+---+---+-------------------+
   |  Name String (Length octets)  |
   +---+---------------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   | Value String (Length octets)  |
   +-------------------------------+
</artwork>
                  </figure>
               </section>
            </section>
         </section>
      </section>
      <section anchor="encoding-strategies" title="Encoding Strategies">
         <section anchor="single-pass-encoding" title="Single pass encoding">
            <t>An encoder making a single pass over a list of headers must choose Base Index before knowing Largest Reference. When trying to reference a header inserted to the table after encoding has begun, the entry is encoded with different instructions that tell the decoder to use an absolute index greater than the Base Index.</t>
         </section>
         <section anchor="evictions" title="Preventing Eviction Races">
            <t>Due to out-of-order arrival, QPACK’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. QPACK employs a two-phase eviction algorithm, in which the encoder will not evict entries that have outstanding (unacknowledged) references.</t>
         </section>
         <section anchor="reference-tracking" title="Reference Tracking">
            <t>An encoder MUST ensure that a header block which references a dynamic table entry is not received by the decoder after the referenced entry has already been evicted. An encoder also respects the limit set by the decoder on the number of streams that are allowed to become blocked. Even if the decoder is willing to tolerate blocked streams, the encoder might choose to avoid them in certain cases.</t>
            <t>In order to enable this, the encoder will need to track outstanding (unacknowledged) header blocks and table updates using feedback received from the decoder.</t>
            <section anchor="blocked-eviction" title="Blocked Eviction">
               <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 Duplicate representation instead (see <xref target="duplicate"/>).</t>
            </section>
            <section anchor="blocked-decoding" title="Blocked Decoding">
               <t>For header blocks encoded in non-blocking mode, the encoder needs to forego indexed representations that refer to table updates which have not yet been acknowledged with <xref target="feedback"/>. Since all table updates are processed in sequence on the control stream, an index into the dynamic table is sufficient to track which entries have been acknowledged.</t>
               <t>To track blocked streams, the necessary Base Index value for each stream can be used. Whenever the decoder processes a table update, it can begin decoding any blocked streams that now have their dependencies satisfied.</t>
            </section>
         </section>
         <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 Duplicate representations for popular header fields (<xref target="duplicate"/>), ensuring they have small indices and hence minimal size on the wire.</t>
         </section>
         <section anchor="sample-one-pass-encoding-algorithm"
                  title="Sample One Pass Encoding Algorithm">
            <t>Pseudo-code for single pass encoding, excluding handling of duplicates, non-blocking mode, and reference tracking.</t>
            <figure>
               <artwork>
baseIndex = dynamicTable.baseIndex
largestReference = 0
for header in headers:
  staticIdx = staticTable.getIndex(header)
  if staticIdx:
    encodeIndexReference(streamBuffer, staticIdx)
    continue

  dynamicIdx = dynamicTable.getIndex(header)
  if !dynamicIdx:
    # No matching entry.  Either insert+index or encode literal
    nameIdx = getNameIndex(header)
    if shouldIndex(header) and dynamicTable.canIndex(header):
      encodeLiteralWithIncrementalIndex(controlBuffer, nameIdx,
                                        header)
      dynamicTable.add(header)
      dynamicIdx = dynamicTable.baseIndex

  if !dynamicIdx:
    # Couldn't index it, literal
    if nameIdx &lt;= staticTable.size:
      encodeLiteral(streamBuffer, nameIndex, header)
    else:
      # encode literal, possibly with nameIdx above baseIndex
      encodeDynamicLiteral(streamBuffer, nameIndex, baseIndex,
                           header)
      largestReference = max(largestReference,
                             dynamicTable.toAbsolute(nameIdx))
  else:
    # Dynamic index reference
    assert(dynamicIdx)
    largestReference = max(largestReference, dynamicIdx)
    # Encode dynamicIdx, possibly with dynamicIdx above baseIndex
    encodeDynamicIndexReference(streamBuffer, dynamicIdx,
                                baseIndex)

# encode the prefix
encodeInteger(prefixBuffer, 0x00, largestReference, 8)
delta = largestReference - baseIndex
sign = delta &gt; 0 ? 0x80 : 0
encodeInteger(prefixBuffer, sign, delta, 7)

return controlBuffer, prefixBuffer + streamBuffer
</artwork>
            </figure>
         </section>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>TBD.</t>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <t>None.</t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="QUIC-HTTP">
            <front>
               <title>Hypertext Transfer Protocol (HTTP) over QUIC</title>
               <author fullname="Mike Bishop" initials="M" surname="Bishop"/>
               <date day="22" month="May" year="2018"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-http-12"/>
         </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>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </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="22" month="May" year="2018"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-transport-12"/>
         </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>
         <reference anchor="RFC2360">
            <front>
               <title>Guide for Internet Standards Writers</title>
               <author fullname="G. Scott" initials="G." surname="Scott"/>
               <date month="June" year="1998"/>
            </front>
            <seriesInfo name="BCP" value="22"/>
            <seriesInfo name="RFC" value="2360"/>
            <seriesInfo name="DOI" value="10.17487/RFC2360"/>
         </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>
      <section anchor="change-log" title="Change Log">
         <t>
            <list style="empty">
               <t>
                  <spanx style="strong">RFC Editor’s Note:</spanx> Please remove this section prior to publication of a final version of this document.</t>
            </list>
         </t>
         <section anchor="since-draft-ietf-quic-qcram-00"
                  title="Since draft-ietf-quic-qcram-00">
            <t>
               <list style="symbols">
                  <t>Separate instruction sets for table updates and header blocks (#1235, #1142, #1141)</t>
                  <t>Reworked indexing scheme (#1176, #1145, #1136, #1130, #1125, #1314)</t>
                  <t>Added mechanisms that support one-pass encoding (#1138, #1320)</t>
                  <t>Added a setting to control the number of blocked decoders (#238, #1140, #1143)</t>
                  <t>Moved table updates and acknowledgments to dedicated streams (#1121, #1122, #1238)</t>
               </list>
            </t>
         </section>
      </section>
   </back>
</rfc>
