<?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-qpack-05"
     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>Netflix</organization>
         <address>
            <email>ckrasic@netflix.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="December" day="18"/>
      <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/3. 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. HTTP/2 uses HPACK (<xref target="RFC7541"/>) for header compression, but QUIC’s stream multiplexing comes into some conflict with HPACK. A key goal of the design of QUIC is to improve stream multiplexing relative to HTTP/2 by reducing head-of-line blocking. If HPACK were used for HTTP/3, it would induce head-of-line blocking due to built-in assumptions of a total ordering across frames on all streams.</t>
         <t>QUIC is described in <xref target="QUIC-TRANSPORT"/>. The HTTP/3 mapping is described in <xref target="HTTP3"/>. For a full description of HTTP/2, see <xref target="RFC7540"/>. The description of HPACK is <xref target="RFC7541"/>.</t>
         <t>QPACK reuses core concepts from HPACK, but is redesigned to allow correctness in the presence of out-of-order delivery, with flexibility for implementations to balance between resilience against head-of-line 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>
         <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 field:">A name-value pair sent as part of an HTTP message.</t>
                  <t hangText="Header list:">An ordered collection of header fields associated with an HTTP message. A header list can contain multiple header fields with the same name. It can also contain duplicate header fields.</t>
                  <t hangText="Header block:">The compressed representation of a header list.</t>
                  <t hangText="Encoder:">An implementation which transforms a header list into a header block.</t>
                  <t hangText="Decoder:">An implementation which transforms a header block into a header list.</t>
                  <t hangText="Absolute Index:">A unique index for each entry in the dynamic table.</t>
                  <t hangText="Base Index:">An absolute index in a header block from which relative indices are made.</t>
                  <t hangText="Largest Reference:">The largest absolute index of an entry referenced in a header block.</t>
               </list>
            </t>
            <t>QPACK is a name, not an acronym.</t>
         </section>
         <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="compression-process-overview"
               title="Compression Process Overview">
         <t>Like HPACK, QPACK uses two tables for associating header fields to indices. The static table (see <xref target="table-static"/>) is predefined and contains common header fields (some of them with an empty value). The dynamic table (see <xref target="table-dynamic"/>) is built up over the course of the connection and can be used by the encoder to index header fields in the encoded header lists.</t>
         <t>QPACK instructions appear in three different types of streams:</t>
         <t>
            <list style="symbols">
               <t>The encoder uses a unidirectional stream to modify the state of the dynamic table without emitting header fields associated with any particular request.</t>
               <t>HEADERS and PUSH_PROMISE frames on request and push streams reference the table state without modifying it.</t>
               <t>The decoder sends feedback to the encoder on a unidirectional stream. This feedback enables the encoder to manage dynamic table state.</t>
            </list>
         </t>
         <section anchor="encoder" title="Encoder">
            <t>An encoder compresses a header list by emitting either an indexed or a literal representation for each header field in the list. References to the static table and literal representations do not require any dynamic state and never risk head-of-line blocking. References to the dynamic table risk head-of-line blocking if the encoder has not received an acknowledgement indicating the entry is available at the decoder.</t>
            <t>An encoder MAY insert any entry in the dynamic table it chooses; it is not limited to header fields it is compressing.</t>
            <t>QPACK preserves the ordering of header fields within each header list. An encoder MUST emit header field representations in the order they appear in the input header list.</t>
            <t>QPACK is designed to contain the more complex state tracking to the encoder, while the decoder is relatively simple.</t>
            <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 been evicted. Hence the encoder needs to track information about each compressed header block that references the dynamic table until that header block is acknowledged by the decoder.</t>
            </section>
            <section anchor="blocked-insertion" title="Blocked Dynamic Table Insertions">
               <t>An encoder MUST NOT insert an entry into the dynamic table (or duplicate an existing entry) if doing so would evict an entry with unacknowledged references. For header blocks that might rely on the newly added entry, the encoder can use a literal representation and maybe insert the entry later.</t>
               <t>To ensure that the encoder is not prevented from adding new entries, the encoder can avoid referencing entries that are close to eviction. Rather than reference such an entry, the encoder can emit a Duplicate instruction (see <xref target="duplicate"/>), and reference the duplicate instead.</t>
               <t>Determining which entries are too close to eviction to reference is an encoder preference. One heuristic is to target a fixed amount of available space in the dynamic table: either unused space or space that can be reclaimed by evicting unreferenced entries. To achieve this, the encoder can maintain a draining index, which is the smallest absolute index in the dynamic table that it will emit a reference for. As new entries are inserted, the encoder increases the draining index to maintain the section of the table that it will not reference. If the encoder does not create new references to entries with an absolute index lower than the draining index, the number of unacknowledged references to those entries will eventually become zero, allowing them to be evicted.</t>
               <figure anchor="fig-draining-index" title="Draining Dynamic Table Entries">
                  <artwork type="drawing">
   +----------+---------------------------------+--------+
   | Draining |          Referenceable          | Unused |
   | Entries  |             Entries             | Space  |
   +----------+---------------------------------+--------+
   ^          ^                                 ^
   |          |                                 |
 Dropping    Draining Index               Base Index /
  Point                                   Insertion Point
</artwork>
               </figure>
            </section>
            <section anchor="overview-hol-avoidance" title="Avoiding Head-of-Line Blocking">
               <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 (<xref target="header-prefix"/>) 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. If the decoder encounters a header block where the actual largest reference is not equal to the Largest Reference declared in the prefix, it MAY treat this as a stream error of type HTTP_QPACK_DECOMPRESSION_FAILED.</t>
               <t>The SETTINGS_QPACK_BLOCKED_STREAMS setting (see <xref target="configuration"/>) specifies an upper bound on the number of streams which can be blocked. 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 MUST treat this as a stream error of type HTTP_QPACK_DECOMPRESSION_FAILED.</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 often 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 could mean using literals. Since literals make the header block larger, this can result in the encoder becoming blocked on congestion or flow control limits.</t>
            </section>
            <section anchor="largest-known-received" title="Largest Known Received">
               <t>In order to identify which dynamic table entries can be safely used without a stream becoming blocked, the encoder tracks the absolute index of the decoder’s Largest Known Received entry.</t>
               <t>When blocking references are permitted, the encoder uses header block acknowledgement to identify the Largest Known Received index, as described in <xref target="header-acknowledgement"/>.</t>
               <t>To acknowledge dynamic table entries which are not referenced by header blocks, for example because the encoder or the decoder have chosen not to risk blocked streams, the decoder sends a Table State Synchronize instruction (see <xref target="table-state-synchronize"/>).</t>
            </section>
         </section>
         <section anchor="decoder" title="Decoder">
            <t>As in HPACK, the decoder processes header blocks and emits the corresponding header lists. It also processes dynamic table modifications from instructions on the encoder stream.</t>
            <t>The decoder MUST emit header fields in the order their representations appear in the input header block.</t>
            <section anchor="state-synchronization" title="State Synchronization">
               <t>The decoder stream (<xref target="decoder-stream"/>) signals key events at the decoder that permit the encoder to track the decoder’s state. These events are:</t>
               <t>
                  <list style="symbols">
                     <t>Complete processing of a header block</t>
                     <t>Abandonment of a stream which might have remaining header blocks</t>
                     <t>Receipt of new dynamic table entries</t>
                  </list>
               </t>
               <t>Knowledge that a header block with references to the dynamic table has been processed permits the encoder to evict entries to which no unacknowledged references remain, regardless of whether those references were potentially blocking (see <xref target="blocked-insertion"/>). When a stream is reset or abandoned, the indication that these header blocks will never be processed serves a similar function; see <xref target="stream-cancellation"/>.</t>
               <t>The decoder chooses when to emit Table State Synchronize instructions (see <xref target="table-state-synchronize"/>). Emitting an instruction after adding each new dynamic table entry will provide the most timely feedback to the encoder, but could be redundant with other decoder feedback. By delaying a Table State Synchronize instruction, the decoder might be able to coalesce multiple Table State Synchronize instructions, or replace them entirely with Header Acknowledgements (see <xref target="header-acknowledgement"/>). However, delaying too long may lead to compression inefficiencies if the encoder waits for an entry to be acknowledged before using it.</t>
            </section>
            <section anchor="blocked-decoding" title="Blocked Decoding">
               <t>To track blocked streams, the necessary Largest Reference 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>
      <section anchor="header-tables" title="Header Tables">
         <t>Unlike in HPACK, entries in the QPACK static and dynamic tables are addressed separately. The following sections describe how entries in each table are addressed.</t>
         <section anchor="table-static" title="Static Table">
            <t>The static table consists of a predefined static list of header fields, each of which has a fixed index over time. Its entries are defined in <xref target="static-table"/>.</t>
            <t>Note the QPACK static table is indexed from 0, whereas the HPACK static table is indexed from 1.</t>
            <t>When the decoder encounters an invalid static table index on a request stream or push stream it MUST treat this as a stream error of type <spanx style="verb">HTTP_QPACK_DECOMPRESSION_FAILED</spanx>. If this index is received on the encoder stream, this MUST be treated as a connection error of type <spanx style="verb">HTTP_QPACK_ENCODER_STREAM_ERROR</spanx>.</t>
         </section>
         <section anchor="table-dynamic" title="Dynamic Table">
            <t>The dynamic table consists of a list of header fields maintained in first-in, first-out order. The dynamic table is initially empty. Entries are added by instructions on the encoder stream (see <xref target="encoder-stream"/>).</t>
            <t>The dynamic table can contain duplicate entries (i.e., entries with the same name and same value). Therefore, duplicate entries MUST NOT be treated as an error by the decoder.</t>
            <section anchor="calculating-table-size" title="Calculating Table Size">
               <t>The size of the dynamic table is the sum of the size of its entries.</t>
               <t>The size of an entry is the sum of its name’s length in bytes (as defined in <xref target="string-literals"/>), its value’s length in bytes, and 32.</t>
               <t>The size of an entry is calculated using the length of its name and value without any Huffman encoding applied.</t>
            </section>
            <section anchor="eviction" title="Eviction">
               <t>Before a new entry is added to the dynamic table, entries are evicted from the end of the dynamic table until the size of the dynamic table is less than or equal to (maximum size - new entry size) or until the table is empty. The encoder MUST NOT evict a dynamic table entry unless it has first been acknowledged by the decoder.</t>
               <t>If the size of the new entry is less than or equal to the maximum size, that entry is added to the table. It is an error to attempt to add an entry that is larger than the maximum size; this MUST be treated as a connection error of type <spanx style="verb">HTTP_QPACK_ENCODER_STREAM_ERROR</spanx>.</t>
               <t>A new entry can reference an entry in the dynamic table that will be evicted when adding this new entry into the dynamic table. Implementations are cautioned to avoid deleting the referenced name if the referenced entry is evicted from the dynamic table prior to inserting the new entry.</t>
               <t>Whenever the maximum size for the dynamic table is reduced by the encoder, entries are evicted from the end of the dynamic table until the size of the dynamic table is less than or equal to the new maximum size. This mechanism can be used to completely clear entries from the dynamic table by setting a maxiumum size of 0, which can subsequently be restored.</t>
            </section>
            <section anchor="maximum-table-size" title="Maximum Table Size">
               <t>The encoder decides how to update the dynamic table size and as such can control how much memory is used by the dynamic table. To limit the memory requirements of the decoder, the dynamic table size is strictly bounded. The decoder determines the maximum size that the encoder is permitted to set for the dynamic table. In HTTP/3, this value is determined by the SETTINGS_HEADER_TABLE_SIZE setting (see <xref target="configuration"/>). The encoder MUST not set a dynamic table size that exceeds this maximum, but it can choose to use a lower dynamic table size (see <xref target="size-update"/>).</t>
               <t>The initial maximum size is determined by the corresponding setting when HTTP requests or responses are first permitted to be sent. For clients using 0-RTT data in HTTP/3, the table size is the remembered value of the setting, even if the server later specifies a larger maximum in its SETTINGS frame. For HTTP/3 servers and HTTP/3 clients when 0-RTT is not attempted or is rejected, the initial maximum table size is the value of the setting in the peer’s SETTINGS frame.</t>
            </section>
            <section anchor="indexing" title="Absolute Indexing">
               <t>Each entry possesses both an absolute index which is fixed for the lifetime of that entry and a relative index which changes based on the context of the reference. The first entry inserted has an absolute index of “1”; indices increase sequentially with each insertion.</t>
            </section>
            <section anchor="relative-indexing" title="Relative Indexing">
               <t>The relative index begins at zero and increases in the opposite direction from the absolute index. Determining which entry has a relative index of “0” depends on the context of the reference.</t>
               <t>On the encoder 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 will change while interpreting instructions on the encoder stream.</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 encoder stream, relative indices are relative to the Base Index at the beginning of the header block (see <xref target="header-prefix"/>). The Base Index is an absolute index. When interpreting the rest of the frame, the entry identified by Base Index has a relative index of zero. The relative indices of entries do not change while interpreting headers on a request or push stream.</t>
               <figure title="Example Dynamic Table Indexing - Relative Index on 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>
            </section>
            <section anchor="post-base-indexing" title="Post-Base Indexing">
               <t>A header block on the request stream can reference entries added after the entry identified by the Base Index. This allows an encoder to process a header block in a single pass and include references to entries added while processing this (or other) header blocks. Newly added entries are referenced using Post-Base instructions. Indices for Post-Base instructions increase in the same direction as absolute indices, but the zero value is one higher than the Base Index.</t>
               <figure title="Example Dynamic Table Indexing - Post-Base Index on Request Stream">
                  <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>
            </section>
            <section anchor="invalid-references" title="Invalid References">
               <t>If the decoder encounters a reference on a request or push stream to a dynamic table entry which has already been evicted or which has an absolute index greater than the declared Largest Reference (see <xref target="header-prefix"/>), it MUST treat this as a stream error of type <spanx style="verb">HTTP_QPACK_DECOMPRESSION_FAILED</spanx>.</t>
               <t>If the decoder encounters a reference on the encoder stream to a dynamic table entry which has already been dropped, it MUST treat this as a connection error of type <spanx style="verb">HTTP_QPACK_ENCODER_STREAM_ERROR</spanx>.</t>
            </section>
         </section>
      </section>
      <section anchor="wire-format" title="Wire Format">
         <section anchor="primitives" title="Primitives">
            <section anchor="prefixed-integers" title="Prefixed Integers">
               <t>The prefixed integer from <xref target="RFC7541" x:fmt="of" x:sec="5.1"/> is used heavily throughout this document. The format from <xref target="RFC7541"/> is used unmodified. QPACK implementations MUST be able to decode integers up to 62 bits long.</t>
            </section>
            <section anchor="string-literals" title="String Literals">
               <t>The string literal defined by <xref target="RFC7541" x:fmt="of" x:sec="5.2"/> is also used throughout. This string format includes optional Huffman encoding.</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 bytes of data. When Huffman encoding is enabled, the Huffman table from <xref target="RFC7541" x:fmt="of" x:sec="B"/> is used without modification.</t>
               <t>This document expands the definition of string literals and permits them 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>
         <section anchor="stream-types" title="Stream Types">
            <t>QPACK instructions occur in three locations, each of which uses a separate instruction space:</t>
            <t>
               <list style="symbols">
                  <t>The encoder stream is a unidirectional stream of type <spanx style="verb">0x48</spanx> (ASCII ‘H’) which carries table updates from encoder to decoder.</t>
                  <t>The decoder stream is a unidirectional stream of type <spanx style="verb">0x68</spanx> (ASCII ‘h’) which carries acknowledgements of table modifications and header processing from decoder to encoder.</t>
                  <t>Finally, the contents of HEADERS and PUSH_PROMISE frames on request streams and push streams reference the QPACK table state.</t>
               </list>
            </t>
            <!-- s/exactly/no more than/  ? -->
            <t>There MUST be exactly one of each unidirectional stream type in each direction. Receipt of a second instance of either stream type MUST be treated as a connection error of HTTP_WRONG_STREAM_COUNT. Closure of either unidirectional stream MUST be treated as a connection error of type HTTP_CLOSED_CRITICAL_STREAM.</t>
            <t>This section describes the instructions which are possible on each stream type.</t>
         </section>
         <section anchor="encoder-stream" title="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>The contents of the encoder stream are an unframed sequence of the following instructions.</t>
            <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 6-bit prefix integer (see <xref target="RFC7541" x:fmt="of" x:sec="5.1"/>) that follows is used to locate the table entry for the header name. When S=1, the number represents the static table index; when S=0, the number is the relative index of the entry in the dynamic table.</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 bytes)  |
   +-------------------------------+
</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 bytes)   |
   +---+---------------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</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="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 described in <xref target="maximum-table-size"/>. In HTTP/3, this limit is the value of the SETTINGS_HEADER_TABLE_SIZE parameter (see <xref target="configuration"/>) received from the decoder. The decoder MUST treat a value that exceeds this limit as a connection error of type <spanx style="verb">HTTP_QPACK_ENCODER_STREAM_ERROR</spanx>.</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"/>). Changing the size of the dynamic table is not acknowledged as this instruction does not insert an entry.</t>
            </section>
         </section>
         <section anchor="decoder-stream" title="Decoder Stream">
            <t>The decoder stream carries information used to ensure consistency of the dynamic table. Information is sent from the decoder to the 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>
            <t>The contents of the decoder stream are an unframed sequence of the following instructions.</t>
            <section anchor="table-state-synchronize" title="Table State Synchronize">
               <t>The Table State Synchronize instruction begins with the ‘00’ two-bit pattern. The instruction specifies the total number of dynamic table inserts and duplications since the last Table State Synchronize or Header Acknowledgement that increased the Largest Known Received dynamic table entry (see <xref target="largest-known-received"/>). This is encoded as a 6-bit prefix integer. The encoder uses this value to determine which table entries might cause a stream to become blocked, as described in <xref target="state-synchronization"/>.</t>
               <figure anchor="fig-size-sync" title="Table State Synchronize">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 |   Insert Count (6+)   |
+---+---+-----------------------+
</artwork>
               </figure>
               <t>An encoder that receives an Insert Count equal to zero or one that increases Largest Known Received beyond what the encoder has sent MUST treat this as a connection error of type <spanx style="verb">HTTP_QPACK_DECODER_STREAM_ERROR</spanx>.</t>
            </section>
            <section anchor="header-acknowledgement" title="Header Acknowledgement">
               <t>After processing a header block whose declared Largest Reference is not zero, the decoder emits a Header Acknowledgement instruction on the decoder stream. The instruction begins with the ‘1’ 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 encoder to know when it is safe to evict an entry, and possibly update Largest Known Received.</t>
               <figure anchor="fig-header-ack" title="Header Acknowledgement">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 1 |      Stream ID (7+)       |
+---+---------------------------+
</artwork>
               </figure>
               <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>
               <t>If an encoder receives a Header Acknowledgement instruction referring to a stream on which every header block with a non-zero Largest Reference has already been acknowledged, that MUST be treated as a connection error of type <spanx style="verb">HTTP_QPACK_DECODER_STREAM_ERROR</spanx>.</t>
               <t>When blocking references are permitted, the encoder uses acknowledgement of header blocks to update the Largest Known Received index. If a header block was potentially blocking, the acknowledgement implies that the decoder has received all dynamic table state necessary to process the header block. If the Largest Reference of an acknowledged header block was greater than the encoder’s current Largest Known Received index, the block’s Largest Reference becomes the new Largest Known Received.</t>
            </section>
            <section anchor="stream-cancellation" title="Stream Cancellation">
               <t>The instruction begins with the ‘01’ two-bit pattern. The instruction includes the stream ID of the affected stream - a request or push stream - encoded as a 6-bit prefix integer.</t>
               <figure anchor="fig-stream-cancel" title="Stream Cancellation">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 1 |     Stream ID (6+)    |
+---+---+-----------------------+
</artwork>
               </figure>
               <t>A stream that is reset might have multiple outstanding header blocks with dynamic table references. When an endpoint receives a stream reset before the end of a stream, it generates a Stream Cancellation instruction on the decoder stream. Similarly, when an endpoint abandons reading of a stream it needs to signal this using the Stream Cancellation instruction. This signals to the encoder that all references to the dynamic table on that stream are no longer outstanding. A decoder with a maximum dynamic table size equal to zero (see <xref target="maximum-table-size"/>) MAY omit sending Stream Cancellations, because the encoder cannot have any dynamic table references.</t>
               <t>An encoder cannot infer from this instruction that any updates to the dynamic table have been received.</t>
            </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="header-prefix" 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>
               <section anchor="largest-reference" title="Largest Reference">
                  <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. If Largest Reference is greater than zero, the encoder transforms it as follows before encoding:</t>
                  <figure>
                     <artwork>
   LargestReference = (LargestReference mod (2 * MaxEntries)) + 1
</artwork>
                  </figure>
                  <t>Here <spanx style="verb">MaxEntries</spanx> is the maximum number of entries that the dynamic table can have. The smallest entry has empty name and value strings and has the size of 32. Hence <spanx style="verb">MaxEntries</spanx> is calculated as</t>
                  <figure>
                     <artwork>
   MaxEntries = floor( MaxTableSize / 32 )
</artwork>
                  </figure>
                  <t>
                     <spanx style="verb">MaxTableSize</spanx> is the maximum size of the dynamic table as specified by the decoder (see <xref target="maximum-table-size"/>).</t>
                  <t>The decoder reconstructs the Largest Reference using the following algorithm:</t>
                  <figure>
                     <artwork>
   if LargestReference &gt; 0:
      LargestReference -= 1
      CurrentWrapped = TotalNumberOfInserts mod (2 * MaxEntries)

      if CurrentWrapped &gt;= LargestReference + MaxEntries:
         # Largest Reference wrapped around 1 extra time
         LargestReference += 2 * MaxEntries
      else if CurrentWrapped + MaxEntries &lt; LargestReference
         # Decoder wrapped around 1 extra time
         CurrentWrapped += 2 * MaxEntries

      LargestReference += TotalNumberOfInserts - CurrentWrapped
</artwork>
                  </figure>
                  <t>TotalNumberOfInserts is the total number of inserts into the decoder’s dynamic table. This encoding limits the length of the prefix on long-lived connections.</t>
               </section>
               <section anchor="base-index" title="Base Index">
                  <t>
                     <spanx style="verb">Base Index</spanx> is used to resolve references in the dynamic table as described in <xref target="relative-indexing"/>.</t>
                  <t>To save space, Base Index is encoded relative to Largest Reference using a one-bit sign and the <spanx style="verb">Delta Base Index</spanx> value. A sign bit of 0 indicates that the Base Index has an absolute index that is greater than or equal to the Largest Reference; the value of Delta Base Index is added to the Largest Reference to determine the absolute value of the Base Index. A sign bit of 1 indicates that the Base Index is less than the Largest Reference. That is:</t>
                  <figure>
                     <artwork>
   if sign == 0:
      baseIndex = largestReference + deltaBaseIndex
   else:
      baseIndex = largestReference - deltaBaseIndex - 1
</artwork>
                  </figure>
                  <t>A single-pass encoder determines the absolute value of Base Index before encoding a header block. If the encoder inserted entries in the dynamic table while encoding the header block, Largest Reference will be greater than Base Index, so the encoded difference is negative and the sign bit is set to 1. If the header block did not reference the most recent entry in the table and did not insert any new entries, Base Index will be greater than the Largest Reference, so the delta will be positive and the sign bit is set to 0.</t>
                  <t>An encoder that produces table updates before encoding a header block might set Largest Reference and Base Index to the same value. In such case, both the sign bit and the Delta Base Index will be set to zero.</t>
                  <t>A header block that does not reference the dynamic table can use any value for Base Index; setting both Largest Reference and Base Index to zero is the most efficient encoding.</t>
               </section>
            </section>
            <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>
            </section>
            <section anchor="indexed-header-field-with-post-base-index"
                     title="Indexed Header Field With Post-Base Index">
               <t>If the entry is in the dynamic table with an absolute index greater than Base Index, the representation starts with the ‘0001’ 4-bit pattern, followed by the post-base index (see <xref target="post-base-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>
               <figure title="Indexed Header Field with Post-Base Index">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 1 |  Index (4+)   |
+---+---+---+---+---------------+
</artwork>
               </figure>
            </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 ‘01’ two-bit pattern. If the entry is in the dynamic table with an absolute index greater than Base Index, the representation starts with the ‘0000’ 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 | 1 | N | S |Name Index (4+)|
   +---+---+---+---+---------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</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>
            </section>
            <section anchor="literal-header-field-with-post-base-name-reference"
                     title="Literal Header Field With Post-Base Name Reference">
               <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="post-base-indexing"/>) encoded as an integer with a 3-bit prefix.</t>
               <figure title="Literal Header Field With Post-Base Name Reference">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | 0 | 0 | N |NameIdx(3+)|
   +---+---+---+---+---+-----------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</artwork>
               </figure>
            </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 ‘001’ 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 | 0 | 1 | N | H |NameLen(3+)|
   +---+---+---+---+---+-----------+
   |  Name String (Length bytes)   |
   +---+---------------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</artwork>
               </figure>
            </section>
         </section>
      </section>
      <section anchor="configuration" title="Configuration">
         <t>QPACK defines two settings which are included in the HTTP/3 SETTINGS frame.</t>
         <t>
            <list style="hanging">
               <t hangText="SETTINGS_HEADER_TABLE_SIZE (0x1):">An integer with a maximum value of 2^30 - 1. The default value is zero bytes. See <xref target="table-dynamic"/> for usage.</t>
               <t hangText="SETTINGS_QPACK_BLOCKED_STREAMS (0x7):">An integer with a maximum value of 2^16 - 1. The default value is zero. See <xref target="overview-hol-avoidance"/>.</t>
            </list>
         </t>
      </section>
      <section anchor="error-handling" title="Error Handling">
         <t>The following error codes are defined for HTTP/3 to indicate failures of QPACK which prevent the stream or connection from continuing:</t>
         <t>
            <list style="hanging">
               <t hangText="HTTP_QPACK_DECOMPRESSION_FAILED (TBD):">The decoder failed to interpret an instruction on a request or push stream and is not able to continue decoding that header block.</t>
               <t hangText="HTTP_QPACK_ENCODER_STREAM_ERROR (TBD):">The decoder failed to interpret an instruction on the encoder stream.</t>
               <t hangText="HTTP_QPACK_DECODER_STREAM_ERROR (TBD):">The encoder failed to interpret an instruction on the decoder stream.</t>
            </list>
         </t>
         <t>Upon encountering an error, an implementation MAY elect to treat it as a connection error even if this document prescribes that it MUST be treated as a stream error.</t>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>TBD.</t>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <section anchor="settings-registration" title="Settings Registration">
            <t>This document creates two new settings in the “HTTP/3 Settings” registry established in <xref target="HTTP3"/>.</t>
            <t>The entries in the following table are registered by this document.</t>
            <texttable>
               <ttcol align="left">Setting Name</ttcol>
               <ttcol align="center">Code</ttcol>
               <ttcol align="left">Specification</ttcol>
               <c>HEADER_TABLE_SIZE</c>
               <c>0x1</c>
               <c>
                  <xref target="configuration"/>
               </c>
               <c>QPACK_BLOCKED_STREAMS</c>
               <c>0x7</c>
               <c>
                  <xref target="configuration"/>
               </c>
            </texttable>
         </section>
         <section anchor="stream-type-registration" title="Stream Type Registration">
            <t>This document creates two new settings in the “HTTP/3 Stream Type” registry established in <xref target="HTTP3"/>.</t>
            <t>The entries in the following table are registered by this document.</t>
            <texttable>
               <ttcol align="left">Stream Type</ttcol>
               <ttcol align="center">Code</ttcol>
               <ttcol align="left">Specification</ttcol>
               <ttcol align="left">Sender</ttcol>
               <c>QPACK Encoder Stream</c>
               <c>0x48</c>
               <c>
                  <xref target="wire-format"/>
               </c>
               <c>Both</c>
               <c>QPACK Decoder Stream</c>
               <c>0x68</c>
               <c>
                  <xref target="wire-format"/>
               </c>
               <c>Both</c>
            </texttable>
         </section>
         <section anchor="error-code-registration" title="Error Code Registration">
            <t>This document establishes the following new error codes in the “HTTP/3 Error Code” registry established in <xref target="HTTP3"/>.</t>
            <texttable>
               <ttcol align="left">Name</ttcol>
               <ttcol align="left">Code</ttcol>
               <ttcol align="left">Description</ttcol>
               <ttcol align="left">Specification</ttcol>
               <c>HTTP_QPACK_DECOMPRESSION_FAILED</c>
               <c>TBD</c>
               <c>Decompression of a header block failed</c>
               <c>
                  <xref target="error-handling"/>
               </c>
               <c>HTTP_QPACK_ENCODER_STREAM_ERROR</c>
               <c>TBD</c>
               <c>Error on the encoder stream</c>
               <c>
                  <xref target="error-handling"/>
               </c>
               <c>HTTP_QPACK_DECODER_STREAM_ERROR</c>
               <c>TBD</c>
               <c>Error on the decoder stream</c>
               <c>
                  <xref target="error-handling"/>
               </c>
            </texttable>
         </section>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="HTTP3">
            <front>
               <title>Hypertext Transfer Protocol Version 3 (HTTP/3)</title>
               <author fullname="Mike Bishop"
                       initials="M."
                       role="editor"
                       surname="Bishop">
                  <organization>Akamai Technologies</organization>
               </author>
               <date/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-http-17"/>
            <x:source basename="draft-ietf-quic-http-17"
                      href="draft-ietf-quic-http-17.xml"/>
         </reference>
         <reference anchor="QUIC-TRANSPORT">
            <front>
               <title>QUIC: A UDP-Based Multiplexed and Secure Transport</title>
               <author fullname="Jana Iyengar"
                       initials="J."
                       role="editor"
                       surname="Iyengar">
                  <organization>Fastly</organization>
               </author>
               <author fullname="Martin Thomson"
                       initials="M."
                       role="editor"
                       surname="Thomson">
                  <organization>Mozilla</organization>
               </author>
               <date/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-transport-17"/>
            <x:source basename="draft-ietf-quic-transport-17"
                      href="draft-ietf-quic-transport-17.xml"/>
         </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="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="static-table" title="Static Table">
         <texttable>
            <ttcol align="left">Index</ttcol>
            <ttcol align="left">Name</ttcol>
            <ttcol align="left">Value</ttcol>
            <c>0</c>
            <c>:authority</c>
            <c> </c>
            <c>1</c>
            <c>:path</c>
            <c>/</c>
            <c>2</c>
            <c>age</c>
            <c>0</c>
            <c>3</c>
            <c>content-disposition</c>
            <c> </c>
            <c>4</c>
            <c>content-length</c>
            <c>0</c>
            <c>5</c>
            <c>cookie</c>
            <c> </c>
            <c>6</c>
            <c>date</c>
            <c> </c>
            <c>7</c>
            <c>etag</c>
            <c> </c>
            <c>8</c>
            <c>if-modified-since</c>
            <c> </c>
            <c>9</c>
            <c>if-none-match</c>
            <c> </c>
            <c>10</c>
            <c>last-modified</c>
            <c> </c>
            <c>11</c>
            <c>link</c>
            <c> </c>
            <c>12</c>
            <c>location</c>
            <c> </c>
            <c>13</c>
            <c>referer</c>
            <c> </c>
            <c>14</c>
            <c>set-cookie</c>
            <c> </c>
            <c>15</c>
            <c>:method</c>
            <c>CONNECT</c>
            <c>16</c>
            <c>:method</c>
            <c>DELETE</c>
            <c>17</c>
            <c>:method</c>
            <c>GET</c>
            <c>18</c>
            <c>:method</c>
            <c>HEAD</c>
            <c>19</c>
            <c>:method</c>
            <c>OPTIONS</c>
            <c>20</c>
            <c>:method</c>
            <c>POST</c>
            <c>21</c>
            <c>:method</c>
            <c>PUT</c>
            <c>22</c>
            <c>:scheme</c>
            <c>http</c>
            <c>23</c>
            <c>:scheme</c>
            <c>https</c>
            <c>24</c>
            <c>:status</c>
            <c>103</c>
            <c>25</c>
            <c>:status</c>
            <c>200</c>
            <c>26</c>
            <c>:status</c>
            <c>304</c>
            <c>27</c>
            <c>:status</c>
            <c>404</c>
            <c>28</c>
            <c>:status</c>
            <c>503</c>
            <c>29</c>
            <c>accept</c>
            <c>*/*</c>
            <c>30</c>
            <c>accept</c>
            <c>application/dns-message</c>
            <c>31</c>
            <c>accept-encoding</c>
            <c>gzip, deflate, br</c>
            <c>32</c>
            <c>accept-ranges</c>
            <c>bytes</c>
            <c>33</c>
            <c>access-control-allow-headers</c>
            <c>cache-control</c>
            <c>34</c>
            <c>access-control-allow-headers</c>
            <c>content-type</c>
            <c>35</c>
            <c>access-control-allow-origin</c>
            <c>*</c>
            <c>36</c>
            <c>cache-control</c>
            <c>max-age=0</c>
            <c>37</c>
            <c>cache-control</c>
            <c>max-age=2592000</c>
            <c>38</c>
            <c>cache-control</c>
            <c>max-age=604800</c>
            <c>39</c>
            <c>cache-control</c>
            <c>no-cache</c>
            <c>40</c>
            <c>cache-control</c>
            <c>no-store</c>
            <c>41</c>
            <c>cache-control</c>
            <c>public, max-age=31536000</c>
            <c>42</c>
            <c>content-encoding</c>
            <c>br</c>
            <c>43</c>
            <c>content-encoding</c>
            <c>gzip</c>
            <c>44</c>
            <c>content-type</c>
            <c>application/dns-message</c>
            <c>45</c>
            <c>content-type</c>
            <c>application/javascript</c>
            <c>46</c>
            <c>content-type</c>
            <c>application/json</c>
            <c>47</c>
            <c>content-type</c>
            <c>application/x-www-form-urlencoded</c>
            <c>48</c>
            <c>content-type</c>
            <c>image/gif</c>
            <c>49</c>
            <c>content-type</c>
            <c>image/jpeg</c>
            <c>50</c>
            <c>content-type</c>
            <c>image/png</c>
            <c>51</c>
            <c>content-type</c>
            <c>text/css</c>
            <c>52</c>
            <c>content-type</c>
            <c>text/html; charset=utf-8</c>
            <c>53</c>
            <c>content-type</c>
            <c>text/plain</c>
            <c>54</c>
            <c>content-type</c>
            <c>text/plain;charset=utf-8</c>
            <c>55</c>
            <c>range</c>
            <c>bytes=0-</c>
            <c>56</c>
            <c>strict-transport-security</c>
            <c>max-age=31536000</c>
            <c>57</c>
            <c>strict-transport-security</c>
            <c>max-age=31536000; includesubdomains</c>
            <c>58</c>
            <c>strict-transport-security</c>
            <c>max-age=31536000; includesubdomains; preload</c>
            <c>59</c>
            <c>vary</c>
            <c>accept-encoding</c>
            <c>60</c>
            <c>vary</c>
            <c>origin</c>
            <c>61</c>
            <c>x-content-type-options</c>
            <c>nosniff</c>
            <c>62</c>
            <c>x-xss-protection</c>
            <c>1; mode=block</c>
            <c>63</c>
            <c>:status</c>
            <c>100</c>
            <c>64</c>
            <c>:status</c>
            <c>204</c>
            <c>65</c>
            <c>:status</c>
            <c>206</c>
            <c>66</c>
            <c>:status</c>
            <c>302</c>
            <c>67</c>
            <c>:status</c>
            <c>400</c>
            <c>68</c>
            <c>:status</c>
            <c>403</c>
            <c>69</c>
            <c>:status</c>
            <c>421</c>
            <c>70</c>
            <c>:status</c>
            <c>425</c>
            <c>71</c>
            <c>:status</c>
            <c>500</c>
            <c>72</c>
            <c>accept-language</c>
            <c> </c>
            <c>73</c>
            <c>access-control-allow-credentials</c>
            <c>FALSE</c>
            <c>74</c>
            <c>access-control-allow-credentials</c>
            <c>TRUE</c>
            <c>75</c>
            <c>access-control-allow-headers</c>
            <c>*</c>
            <c>76</c>
            <c>access-control-allow-methods</c>
            <c>get</c>
            <c>77</c>
            <c>access-control-allow-methods</c>
            <c>get, post, options</c>
            <c>78</c>
            <c>access-control-allow-methods</c>
            <c>options</c>
            <c>79</c>
            <c>access-control-expose-headers</c>
            <c>content-length</c>
            <c>80</c>
            <c>access-control-request-headers</c>
            <c>content-type</c>
            <c>81</c>
            <c>access-control-request-method</c>
            <c>get</c>
            <c>82</c>
            <c>access-control-request-method</c>
            <c>post</c>
            <c>83</c>
            <c>alt-svc</c>
            <c>clear</c>
            <c>84</c>
            <c>authorization</c>
            <c> </c>
            <c>85</c>
            <c>content-security-policy</c>
            <c>script-src 'none'; object-src 'none'; base-uri 'none'</c>
            <c>86</c>
            <c>early-data</c>
            <c>1</c>
            <c>87</c>
            <c>expect-ct</c>
            <c> </c>
            <c>88</c>
            <c>forwarded</c>
            <c> </c>
            <c>89</c>
            <c>if-range</c>
            <c> </c>
            <c>90</c>
            <c>origin</c>
            <c> </c>
            <c>91</c>
            <c>purpose</c>
            <c>prefetch</c>
            <c>92</c>
            <c>server</c>
            <c> </c>
            <c>93</c>
            <c>timing-allow-origin</c>
            <c>*</c>
            <c>94</c>
            <c>upgrade-insecure-requests</c>
            <c>1</c>
            <c>95</c>
            <c>user-agent</c>
            <c> </c>
            <c>96</c>
            <c>x-forwarded-for</c>
            <c> </c>
            <c>97</c>
            <c>x-frame-options</c>
            <c>deny</c>
            <c>98</c>
            <c>x-frame-options</c>
            <c>sameorigin</c>
         </texttable>
      </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)
if baseIndex &gt;= largestReference:
  encodeInteger(prefixBuffer, 0, baseIndex - largestReference, 7)
else:
  encodeInteger(prefixBuffer, 0x80,
                largestReference  - baseIndex, 7)

return controlBuffer, prefixBuffer + streamBuffer
</artwork>
         </figure>
      </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-qpack-04"
                  title="Since draft-ietf-quic-qpack-04">
            <t>
               <list style="symbols">
                  <t>Changed calculation of Delta Base Index to avoid an illegal value (#2002, #2005)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-03"
                  title="Since draft-ietf-quic-qpack-03">
            <t>
               <list style="symbols">
                  <t>Change HTTP settings defaults (#2038)</t>
                  <t>Substantial editorial reorganization</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-02"
                  title="Since draft-ietf-quic-qpack-02">
            <t>
               <list style="symbols">
                  <t>Largest Reference encoded modulo MaxEntries (#1763)</t>
                  <t>New Static Table (#1355)</t>
                  <t>Table Size Update with Insert Count=0 is a connection error (#1762)</t>
                  <t>Stream Cancellations are optional when SETTINGS_HEADER_TABLE_SIZE=0 (#1761)</t>
                  <t>Implementations must handle 62 bit integers (#1760)</t>
                  <t>Different error types for each QPACK stream, other changes to error handling (#1726)</t>
                  <t>Preserve header field order (#1725)</t>
                  <t>Initial table size is the maximum permitted when table is first usable (#1642)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-01"
                  title="Since draft-ietf-quic-qpack-01">
            <t>
               <list style="symbols">
                  <t>Only header blocks that reference the dynamic table are acknowledged (#1603, #1605)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-00"
                  title="Since draft-ietf-quic-qpack-00">
            <t>
               <list style="symbols">
                  <t>Renumbered instructions for consistency (#1471, #1472)</t>
                  <t>Decoder is allowed to validate largest reference (#1404, #1469)</t>
                  <t>Header block acknowledgments also acknowledge the associated largest reference (#1370, #1400)</t>
                  <t>Added an acknowledgment for unread streams (#1371, #1400)</t>
                  <t>Removed framing from encoder stream (#1361,#1467)</t>
                  <t>Control streams use typed unidirectional streams rather than fixed stream IDs (#910,#1359)</t>
               </list>
            </t>
         </section>
         <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>
      <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>
         <t>Buck’s contribution was supported by Google during his employment there.</t>
         <t>A substantial portion of Mike’s contribution was supported by Microsoft during his employment there.</t>
      </section>
   </back>
</rfc>
