<?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.3.12 -->
<?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-18"
     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/3</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="2020" month="September" day="25"/>
      <area>Transport</area>
      <workgroup>QUIC</workgroup>
      <abstract>
         <t>This specification defines QPACK, a compression format for efficiently representing HTTP fields, to be used in HTTP/3. This is a variation of HPACK 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 (<eref target="mailto:quic@ietf.org">quic@ietf.org</eref>), which is archived at <eref target="https://mailarchive.ietf.org/arch/search/?email_list=quic"/>.</t>
         <t>Working Group information can be found at <eref target="https://github.com/quicwg"/>; source code and issues list for this draft can be found at <eref target="https://github.com/quicwg/base-drafts/labels/-qpack"/>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>The QUIC transport protocol (<xref target="QUIC-TRANSPORT"/>) is designed to support HTTP semantics, and its design subsumes many of the features of HTTP/2 (<xref target="RFC7540"/>). HTTP/2 uses HPACK (<xref target="RFC7541"/>) for compression of the header and trailer sections. If HPACK were used for HTTP/3 (<xref target="HTTP3"/>), it would induce head-of-line blocking for field sections due to built-in assumptions of a total ordering across frames on all streams.</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="HTTP fields:">Metadata sent as part of an HTTP message. The term encompasses both header and trailer fields. Colloquially, the term “headers” has often been used to refer to HTTP header fields and trailer fields; this document uses “fields” for generality.</t>
                  <t hangText="HTTP field line:">A name-value pair sent as part of an HTTP field section. See <xref target="SEMANTICS" x:fmt="of" x:sec="5"><?aug-anchor header.and.trailer.fields?><?aug-title Header and Trailer Fields?></xref>.</t>
                  <t hangText="HTTP field value:">Data associated with a field name, composed from all field line values with that field name in that section, concatenated together and separated with commas.</t>
                  <t hangText="Field section:">An ordered collection of HTTP field lines associated with an HTTP message. A field section can contain multiple field lines with the same name. It can also contain duplicate field lines. An HTTP message can include both header field and trailer field sections.</t>
                  <t hangText="Representation:">An instruction that represents a field line, possibly by reference to the dynamic and static tables.</t>
                  <t hangText="Encoder:">An implementation that encodes field sections.</t>
                  <t hangText="Decoder:">An implementation that decodes encoded field sections.</t>
                  <t hangText="Absolute Index:">A unique index for each entry in the dynamic table.</t>
                  <t hangText="Base:">A reference point for relative and post-base indices. Representations that reference dynamic table entries are relative to a Base.</t>
                  <t hangText="Insert Count:">The total number of entries inserted in the dynamic table.</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="prefixed-integers"/>, 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 field lines (“headers”) to indices. The static table (<xref target="header-table-static"/>) is predefined and contains common header field lines (some of them with an empty value). The dynamic table (<xref target="header-table-dynamic"/>) is built up over the course of the connection and can be used by the encoder to index both header and trailer field lines in the encoded field sections.</t>
         <t>QPACK defines unidirectional streams for sending instructions from encoder to decoder and vice versa.</t>
         <section anchor="encoder" title="Encoder">
            <t>An encoder converts a header or trailer field section into a series of representations by emitting either an indexed or a literal representation for each field line in the list; see <xref target="field-line-representations"/>. Indexed representations achieve high compression by replacing the literal name and possibly the value with an index to either the static or dynamic table. 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 field lines it is compressing.</t>
            <t>QPACK preserves the ordering of field lines within each field section. An encoder MUST emit field representations in the order they appear in the input field section.</t>
            <t>QPACK is designed to contain the more complex state tracking to the encoder, while the decoder is relatively simple.</t>
            <section anchor="blocked-insertion" title="Limits on Dynamic Table Insertions">
               <t>Inserting entries into the dynamic table might not be possible if the table contains entries that cannot be evicted.</t>
               <t>A dynamic table entry cannot be evicted immediately after insertion, even if it has never been referenced. Once the insertion of a dynamic table entry has been acknowledged and there are no outstanding references to the entry in unacknowledged representations, the entry becomes evictable. Note that references on the encoder stream never preclude the eviction of an entry, because those references are guaranteed to be processed before the instruction evicting the entry.</t>
               <t>If the dynamic table does not contain enough room for a new entry without evicting other entries, and the entries that would be evicted are not evictable, the encoder MUST NOT insert that entry into the dynamic table (including duplicates of existing entries). In order to avoid this, an encoder that uses the dynamic table has to keep track of each dynamic table entry referenced by each field section until those representations are acknowledged by the decoder; see <xref target="header-acknowledgement"/>.</t>
               <section anchor="avoiding-prohibited-insertions"
                        title="Avoiding Prohibited Insertions">
                  <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 (<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 non-blocking entries. To achieve this, the encoder can maintain a draining index, which is the smallest absolute index (<xref target="indexing"/>) 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">
   +--------+---------------------------------+----------+
   | Unused |          Referenceable          | Draining |
   | Space  |             Entries             | Entries  |
   +--------+---------------------------------+----------+
            ^                                 ^          ^
            |                                 |          |
      Insertion Point                 Draining Index  Dropping
                                                       Point
</artwork>
                  </figure>
               </section>
            </section>
            <section anchor="blocked-streams" title="Blocked Streams">
               <t>Because QUIC does not guarantee order between data on different streams, a decoder might encounter a representation that references a dynamic table entry that it has not yet received.</t>
               <t>Each encoded field section contains a Required Insert Count (<xref target="header-prefix"/>), the lowest possible value for the Insert Count with which the field section can be decoded. For a field section encoded using references to the dynamic table, the Required Insert Count is one larger than the largest absolute index of all referenced dynamic table entries. For a field section encoded with no references to the dynamic table, the Required Insert Count is zero.</t>
               <t>When the decoder receives an encoded field section with a Required Insert Count greater than its own Insert Count, the stream cannot be processed immediately, and is considered “blocked”; see <xref target="blocked-decoding"/>.</t>
               <t>The decoder specifies an upper bound on the number of streams that can be blocked using the SETTINGS_QPACK_BLOCKED_STREAMS setting; see <xref target="configuration"/>. An encoder MUST limit the number of streams that could become blocked to the value of SETTINGS_QPACK_BLOCKED_STREAMS at all times. If a decoder encounters more blocked streams than it promised to support, it MUST treat this as a connection error of type QPACK_DECOMPRESSION_FAILED.</t>
               <t>Note that the decoder might not become blocked on every stream that risks becoming 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 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 can avoid the risk of blocking by only referencing dynamic table entries that have been acknowledged, but this could mean using literals. Since literals make the encoded field section larger, this can result in the encoder becoming blocked on congestion or flow control limits.</t>
            </section>
            <section anchor="avoiding-flow-control-deadlocks"
                     title="Avoiding Flow Control Deadlocks">
               <t>Writing instructions on streams that are limited by flow control can produce deadlocks.</t>
               <t>A decoder might stop issuing flow control credit on the stream that carries an encoded field section until the necessary updates are received on the encoder stream. If the granting of flow control credit on the encoder stream (or the connection as a whole) depends on the consumption and release of data on the stream carrying the encoded field section, a deadlock might result.</t>
               <t>More generally, a stream containing a large instruction can become deadlocked if the decoder withholds flow control credit until the instruction is completely received.</t>
               <t>To avoid these deadlocks, an encoder SHOULD avoid writing an instruction unless sufficient stream and connection flow control credit is available for the entire instruction.</t>
            </section>
            <section anchor="known-received-count" title="Known Received Count">
               <t>The Known Received Count is the total number of dynamic table insertions and duplications acknowledged by the decoder. The encoder tracks the Known Received Count in order to identify which dynamic table entries can be referenced without potentially blocking a stream. The decoder tracks the Known Received Count in order to be able to send Insert Count Increment instructions.</t>
               <t>A Section Acknowledgement instruction (<xref target="header-acknowledgement"/>) implies that the decoder has received all dynamic table state necessary to decode the field section. If the Required Insert Count of the acknowledged field section is greater than the current Known Received Count, Known Received Count is updated to the value of the Required Insert Count.</t>
               <t>An Insert Count Increment instruction (<xref target="insert-count-increment"/>) increases the Known Received Count by its Increment parameter. See <xref target="new-table-entries"/> for guidance.</t>
            </section>
         </section>
         <section anchor="decoder" title="Decoder">
            <t>As in HPACK, the decoder processes a series of representations and emits the corresponding field sections. It also processes instructions received on the encoder stream that modify the dynamic table. Note that encoded field sections and encoder stream instructions arrive on separate streams. This is unlike HPACK, where encoded field sections (header blocks) can contain instructions that modify the dynamic table, and there is no dedicated stream of HPACK instructions.</t>
            <t>The decoder MUST emit field lines in the order their representations appear in the encoded field section.</t>
            <section anchor="blocked-decoding" title="Blocked Decoding">
               <t>Upon receipt of an encoded field section, the decoder examines the Required Insert Count. When the Required Insert Count is less than or equal to the decoder’s Insert Count, the field section can be processed immediately. Otherwise, the stream on which the field section was received becomes blocked.</t>
               <t>While blocked, encoded field section data SHOULD remain in the blocked stream’s flow control window. A stream becomes unblocked when the Insert Count becomes greater than or equal to the Required Insert Count for all encoded field sections the decoder has started reading from the stream.</t>
               <t>When processing encoded field sections, the decoder expects the Required Insert Count to equal the lowest possible value for the Insert Count with which the field section can be decoded, as prescribed in <xref target="blocked-streams"/>. If it encounters a Required Insert Count smaller than expected, it MUST treat this as a connection error of type QPACK_DECOMPRESSION_FAILED; see <xref target="invalid-references"/>. If it encounters a Required Insert Count larger than expected, it MAY treat this as a connection error of type QPACK_DECOMPRESSION_FAILED.</t>
            </section>
            <section anchor="state-synchronization" title="State Synchronization">
               <t>The decoder signals the following events by emitting decoder instructions (<xref target="decoder-instructions"/>) on the decoder stream.</t>
               <section anchor="completed-processing-of-a-field-section"
                        title="Completed Processing of a Field Section">
                  <t>After the decoder finishes decoding a field section encoded using representations containing dynamic table references, it MUST emit a Section Acknowledgement instruction (<xref target="header-acknowledgement"/>). A stream may carry multiple field sections in the case of intermediate responses, trailers, and pushed requests. The encoder interprets each Section Acknowledgement instruction as acknowledging the earliest unacknowledged field section containing dynamic table references sent on the given stream.</t>
               </section>
               <section anchor="abandonment-of-a-stream" title="Abandonment of a Stream">
                  <t>When an endpoint receives a stream reset before the end of a stream or before all encoded field sections are processed on that stream, or when it abandons reading of a stream, it generates a Stream Cancellation instruction; see <xref target="stream-cancellation"/>. 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 capacity (<xref target="maximum-dynamic-table-capacity"/>) equal to zero MAY omit sending Stream Cancellations, because the encoder cannot have any dynamic table references. An encoder cannot infer from this instruction that any updates to the dynamic table have been received.</t>
                  <t>The Section Acknowledgement and Stream Cancellation instructions permit the encoder to remove references to entries in the dynamic table. When an entry with absolute index lower than the Known Received Count has zero references, then it is considered evictable; see <xref target="blocked-insertion"/>.</t>
               </section>
               <section anchor="new-table-entries" title="New Table Entries">
                  <t>After receiving new table entries on the encoder stream, the decoder chooses when to emit Insert Count Increment instructions; see <xref target="insert-count-increment"/>. Emitting this instruction after adding each new dynamic table entry will provide the timeliest feedback to the encoder, but could be redundant with other decoder feedback. By delaying an Insert Count Increment instruction, the decoder might be able to coalesce multiple Insert Count Increment instructions, or replace them entirely with Section 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>
            <section anchor="invalid-references" title="Invalid References">
               <t>If the decoder encounters a reference in a field line representation to a dynamic table entry that has already been evicted or that has an absolute index greater than or equal to the declared Required Insert Count (<xref target="header-prefix"/>), it MUST treat this as a connection error of type QPACK_DECOMPRESSION_FAILED.</t>
               <t>If the decoder encounters a reference in an encoder instruction to a dynamic table entry that has already been evicted, it MUST treat this as a connection error of type QPACK_ENCODER_STREAM_ERROR.</t>
            </section>
         </section>
      </section>
      <section anchor="reference-tables" title="Reference 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="header-table-static" title="Static Table">
            <t>The static table consists of a predefined list of field lines, each of which has a fixed index over time. Its entries are defined in <xref target="static-table"/>.</t>
            <t>All entries in the static table have a name and a value. However, values can be empty (that is, have a length of 0). Each entry is identified by a unique index.</t>
            <t>Note that 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 in a field line representation it MUST treat this as a connection error of type QPACK_DECOMPRESSION_FAILED. If this index is received on the encoder stream, this MUST be treated as a connection error of type QPACK_ENCODER_STREAM_ERROR.</t>
         </section>
         <section anchor="header-table-dynamic" title="Dynamic Table">
            <t>The dynamic table consists of a list of field lines maintained in first-in, first-out order. Each HTTP/3 endpoint holds a dynamic table that is initially empty. Entries are added by encoder instructions received on the encoder stream; see <xref target="encoder-instructions"/>.</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>
            <t>Dynamic table entries can have empty values.</t>
            <section anchor="dynamic-table-size" title="Dynamic 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, its value’s length in bytes, and 32. The size of an entry is calculated using the length of its name and value without Huffman encoding applied.</t>
            </section>
            <section anchor="eviction" title="Dynamic Table Capacity and Eviction">
               <t>The encoder sets the capacity of the dynamic table, which serves as the upper limit on its size. The initial capacity of the dynamic table is zero. The encoder sends a Set Dynamic Table Capacity instruction (<xref target="set-dynamic-capacity"/>) with a non-zero capacity to begin using the dynamic table.</t>
               <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 (table capacity - size of new entry). The encoder MUST NOT cause a dynamic table entry to be evicted unless that entry is evictable; see <xref target="blocked-insertion"/>. The new entry is then added to the table. It is an error if the encoder attempts to add an entry that is larger than the dynamic table capacity; the decoder MUST treat this as a connection error of type QPACK_ENCODER_STREAM_ERROR.</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 or value if the referenced entry is evicted from the dynamic table prior to inserting the new entry.</t>
               <t>Whenever the dynamic table capacity is reduced by the encoder (<xref target="set-dynamic-capacity"/>), 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 table capacity. This mechanism can be used to completely clear entries from the dynamic table by setting a capacity of 0, which can subsequently be restored.</t>
            </section>
            <section anchor="maximum-dynamic-table-capacity"
                     title="Maximum Dynamic Table Capacity">
               <t>To bound the memory requirements of the decoder, the decoder limits the maximum value the encoder is permitted to set for the dynamic table capacity. In HTTP/3, this limit is determined by the value of SETTINGS_QPACK_MAX_TABLE_CAPACITY sent by the decoder; see <xref target="configuration"/>. The encoder MUST NOT set a dynamic table capacity that exceeds this maximum, but it can choose to use a lower dynamic table capacity; see <xref target="set-dynamic-capacity"/>.</t>
               <t>For clients using 0-RTT data in HTTP/3, the server’s maximum table capacity is the remembered value of the setting, or zero if the value was not previously sent. When the client’s 0-RTT value of the SETTING is zero, the server MAY set it to a non-zero value in its SETTINGS frame. If the remembered value is non-zero, the server MUST send the same non-zero value in its SETTINGS frame. If it specifies any other value, or omits SETTINGS_QPACK_MAX_TABLE_CAPACITY from SETTINGS, the encoder must treat this as a connection error of type QPACK_DECODER_STREAM_ERROR.</t>
               <t>For HTTP/3 servers and HTTP/3 clients when 0-RTT is not attempted or is rejected, the maximum table capacity is 0 until the encoder processes a SETTINGS frame with a non-zero value of SETTINGS_QPACK_MAX_TABLE_CAPACITY.</t>
               <t>When the maximum table capacity is zero, the encoder MUST NOT insert entries into the dynamic table, and MUST NOT send any encoder instructions on the encoder stream.</t>
            </section>
            <section anchor="indexing" title="Absolute Indexing">
               <t>Each entry possesses an absolute index that is fixed for the lifetime of that entry. The first entry inserted has an absolute index of “0”; indices increase by one with each insertion.</t>
            </section>
            <section anchor="relative-indexing" title="Relative Indexing">
               <t>Relative indices begin at zero and increase 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>In encoder instructions (<xref target="encoder-instructions"/>), a relative index of “0” 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 - Encoder Stream">
                  <artwork type="drawing">
      +-----+---------------+-------+
      | n-1 |      ...      |   d   |  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>Unlike in encoder instructions, relative indices in field line representations are relative to the Base at the beginning of the encoded field section; see <xref target="header-prefix"/>. This ensures that references are stable even if encoded field sections and dynamic table updates are processed out of order.</t>
               <t>In a field line representation, a relative index of “0” refers to the entry with absolute index equal to Base - 1.</t>
               <figure title="Example Dynamic Table Indexing - Relative Index in Representation">
                  <artwork type="drawing">
               Base
                |
                V
    +-----+-----+-----+-----+-------+
    | n-1 | n-2 | n-3 | ... |   d   |  Absolute Index
    +-----+-----+  -  +-----+   -   +
                |  0  | ... | n-d-3 |  Relative Index
                +-----+-----+-------+

n = count of entries inserted
d = count of entries dropped
In this example, Base = n - 2
</artwork>
               </figure>
            </section>
            <section anchor="post-base" title="Post-Base Indexing">
               <t>Post-Base indices are used in field line representations for entries with absolute indices greater than or equal to Base, starting at 0 for the entry with absolute index equal to Base, and increasing in the same direction as the absolute index.</t>
               <t>Post-Base indices allow an encoder to process a field section in a single pass and include references to entries added while processing this (or other) field sections.</t>
               <figure title="Example Dynamic Table Indexing - Post-Base Index in Representation">
                  <artwork type="drawing">
               Base
                |
                V
    +-----+-----+-----+-----+-----+
    | n-1 | n-2 | n-3 | ... |  d  |  Absolute Index
    +-----+-----+-----+-----+-----+
    |  1  |  0  |                    Post-Base Index
    +-----+-----+

n = count of entries inserted
d = count of entries dropped
In this example, Base = n - 2
</artwork>
               </figure>
            </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. Note, however, that QPACK uses some prefix sizes not actually used in HPACK.</t>
               <t>QPACK implementations MUST be able to decode integers up to and including 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 bit flag, denoted as ‘H’ in this document (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 by permitting 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 prefix size, N, can have a value between 2 and 8 inclusive. 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="enc-dec-stream-def" title="Encoder and Decoder Streams">
            <t>QPACK defines two unidirectional stream types:</t>
            <t>
               <list style="symbols">
                  <t>An encoder stream is a unidirectional stream of type 0x02. It carries an unframed sequence of encoder instructions from encoder to decoder.</t>
                  <t>A decoder stream is a unidirectional stream of type 0x03. It carries an unframed sequence of decoder instructions from decoder to encoder.</t>
               </list>
            </t>
            <t>HTTP/3 endpoints contain a QPACK encoder and decoder. Each endpoint MUST initiate at most one encoder stream and at most one decoder stream. Receipt of a second instance of either stream type MUST be treated as a connection error of type H3_STREAM_CREATION_ERROR. These streams MUST NOT be closed. Closure of either unidirectional stream type MUST be treated as a connection error of type H3_CLOSED_CRITICAL_STREAM.</t>
            <t>An endpoint MAY avoid creating an encoder stream if it will not be used (for example if its encoder does not wish to use the dynamic table, or if the maximum size of the dynamic table permitted by the peer is zero).</t>
            <t>An endpoint MAY avoid creating a decoder stream if its decoder sets the maximum capacity of the dynamic table to zero.</t>
            <t>An endpoint MUST allow its peer to create an encoder stream and a decoder stream even if the connection’s settings prevent their use.</t>
         </section>
         <section anchor="encoder-instructions" title="Encoder Instructions">
            <t>An encoder sends encoder instructions on the encoder stream to set the capacity of the dynamic table and add dynamic table entries. Instructions adding table entries can use 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 that already exist in the dynamic table, the full entry can also be used by reference, creating a duplicate entry.</t>
            <section anchor="set-dynamic-capacity" title="Set Dynamic Table Capacity">
               <t>An encoder informs the decoder of a change to the dynamic table capacity using an instruction that begins with the ‘001’ three-bit pattern. This is followed by the new dynamic table capacity represented as an integer with a 5-bit prefix; see <xref target="prefixed-integers"/>.</t>
               <figure anchor="fig-set-capacity" title="Set Dynamic Table Capacity">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 |   Capacity (5+)   |
+---+---+---+-------------------+
</artwork>
               </figure>
               <t>The new capacity MUST be lower than or equal to the limit described in <xref target="maximum-dynamic-table-capacity"/>. In HTTP/3, this limit is the value of the SETTINGS_QPACK_MAX_TABLE_CAPACITY parameter (<xref target="configuration"/>) received from the decoder. The decoder MUST treat a new dynamic table capacity value that exceeds this limit as a connection error of type QPACK_ENCODER_STREAM_ERROR.</t>
               <t>Reducing the dynamic table capacity can cause entries to be evicted; see <xref target="eviction"/>. This MUST NOT cause the eviction of entries that are not evictable; see <xref target="blocked-insertion"/>. Changing the capacity of the dynamic table is not acknowledged as this instruction does not insert an entry.</t>
            </section>
            <section anchor="insert-with-name-reference" title="Insert With Name Reference">
               <t>An encoder adds an entry to the dynamic table where the field name matches the field name of an entry stored in the static or the dynamic table using an instruction that starts with the ‘1’ one-bit pattern. The second (‘T’) bit indicates whether the reference is to the static or dynamic table. The 6-bit prefix integer (<xref target="prefixed-integers"/>) that follows is used to locate the table entry for the field name. When T=1, the number represents the static table index; when T=0, the number is the relative index of the entry in the dynamic table.</t>
               <t>The field name reference is followed by the field value represented as a string literal; see <xref target="string-literals"/>.</t>
               <figure title="Insert Field Line -- Indexed Name">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 1 | T |    Name Index (6+)    |
   +---+---+-----------------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</artwork>
               </figure>
            </section>
            <section anchor="insert-with-literal-name" title="Insert With Literal Name">
               <t>An encoder adds an entry to the dynamic table where both the field name and the field value are represented as string literals using an instruction that starts with the ‘01’ two-bit pattern.</t>
               <t>This is followed by the name represented as a 6-bit prefix string literal, and the value represented as an 8-bit prefix string literal; see <xref target="string-literals"/>.</t>
               <figure title="Insert Field Line -- 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>An encoder duplicates an existing entry in the dynamic table using an instruction that begins with the ‘000’ three-bit pattern. This is followed by the relative index of the existing entry represented as an integer with a 5-bit prefix; see <xref target="prefixed-integers"/>.</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 avoid adding a reference to an older entry, which might block inserting new entries.</t>
            </section>
         </section>
         <section anchor="decoder-instructions" title="Decoder Instructions">
            <t>A decoder sends decoder instructions on the decoder stream to inform the encoder about the processing of field sections and table updates to ensure consistency of the dynamic table.</t>
            <section anchor="header-acknowledgement" title="Section Acknowledgement">
               <t>After processing an encoded field section whose declared Required Insert Count is not zero, the decoder emits a Section Acknowledgement instruction. The instruction begins with the ‘1’ one-bit pattern, followed by the field section’s associated stream ID encoded as a 7-bit prefix integer; see <xref target="prefixed-integers"/>.</t>
               <t>This instruction is used as described in <xref target="known-received-count"/> and in <xref target="state-synchronization"/>.</t>
               <figure anchor="fig-header-ack" title="Section Acknowledgement">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 1 |      Stream ID (7+)       |
+---+---------------------------+
</artwork>
               </figure>
               <t>If an encoder receives a Section Acknowledgement instruction referring to a stream on which every encoded field section with a non-zero Required Insert Count has already been acknowledged, this MUST be treated as a connection error of type QPACK_DECODER_STREAM_ERROR.</t>
               <t>The Section Acknowledgement instruction might increase the Known Received Count; see <xref target="known-received-count"/>.</t>
            </section>
            <section anchor="stream-cancellation" title="Stream Cancellation">
               <t>When a stream is reset or reading is abandoned, the decoder emits a Stream Cancellation instruction. The instruction begins with the ‘01’ two-bit pattern, followed by the stream ID of the affected stream encoded as a 6-bit prefix integer.</t>
               <t>This instruction is used as described in <xref target="state-synchronization"/>.</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>
            </section>
            <section anchor="insert-count-increment" title="Insert Count Increment">
               <t>The Insert Count Increment instruction begins with the ‘00’ two-bit pattern, followed by the Increment encoded as a 6-bit prefix integer. This instruction increases the Known Received Count (<xref target="known-received-count"/>) by the value of the Increment parameter. The decoder should send an Increment value that increases the Known Received Count to the total number of dynamic table insertions and duplications processed so far.</t>
               <figure anchor="fig-size-sync" title="Insert Count Increment">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 |     Increment (6+)    |
+---+---+-----------------------+
</artwork>
               </figure>
               <t>An encoder that receives an Increment field equal to zero, or one that increases the Known Received Count beyond what the encoder has sent MUST treat this as a connection error of type QPACK_DECODER_STREAM_ERROR.</t>
            </section>
         </section>
         <section anchor="field-line-representations" title="Field Line Representations">
            <t>An encoded field section consists of a prefix and a possibly empty sequence of representations defined in this section. Each representation corresponds to a single field line. These representations reference the static table or the dynamic table in a particular state, but do not modify that state.</t>
            <t>Encoded field sections are carried in frames on streams defined by the enclosing protocol.</t>
            <section anchor="header-prefix" title="Encoded Field Section Prefix">
               <t>Each encoded field section is prefixed with two integers. The Required Insert Count is encoded as an integer with an 8-bit prefix using the encoding described in <xref target="ric"/>. The Base is encoded as a sign bit (‘S’) and a Delta Base value with a 7-bit prefix; see <xref target="base"/>.</t>
               <figure anchor="fig-base-index" title="Encoded Field Section">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
|   Required Insert Count (8+)  |
+---+---------------------------+
| S |      Delta Base (7+)      |
+---+---------------------------+
|      Encoded Field Lines    ...
+-------------------------------+
</artwork>
               </figure>
               <section anchor="ric" title="Required Insert Count">
                  <t>Required Insert Count identifies the state of the dynamic table needed to process the encoded field section. Blocking decoders use the Required Insert Count to determine when it is safe to process the rest of the field section.</t>
                  <t>The encoder transforms the Required Insert Count as follows before encoding:</t>
                  <figure>
                     <artwork>
   if ReqInsertCount == 0:
      EncInsertCount = 0
   else:
      EncInsertCount = (ReqInsertCount 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( MaxTableCapacity / 32 )
</artwork>
                  </figure>
                  <t>
                     <spanx style="verb">MaxTableCapacity</spanx> is the maximum capacity of the dynamic table as specified by the decoder; see <xref target="maximum-dynamic-table-capacity"/>.</t>
                  <t>This encoding limits the length of the prefix on long-lived connections.</t>
                  <t>The decoder can reconstruct the Required Insert Count using an algorithm such as the following. If the decoder encounters a value of EncodedInsertCount that could not have been produced by a conformant encoder, it MUST treat this as a connection error of type QPACK_DECOMPRESSION_FAILED.</t>
                  <t>TotalNumberOfInserts is the total number of inserts into the decoder’s dynamic table.</t>
                  <figure>
                     <artwork>
   FullRange = 2 * MaxEntries
   if EncodedInsertCount == 0:
      ReqInsertCount = 0
   else:
      if EncodedInsertCount &gt; FullRange:
         Error
      MaxValue = TotalNumberOfInserts + MaxEntries

      # MaxWrapped is the largest possible value of
      # ReqInsertCount that is 0 mod 2*MaxEntries
      MaxWrapped = floor(MaxValue / FullRange) * FullRange
      ReqInsertCount = MaxWrapped + EncodedInsertCount - 1

      # If ReqInsertCount exceeds MaxValue, the Encoder's value
      # must have wrapped one fewer time
      if ReqInsertCount &gt; MaxValue:
         if ReqInsertCount &lt;= FullRange:
            Error
         ReqInsertCount -= FullRange

      # Value of 0 must be encoded as 0.
      if ReqInsertCount == 0:
         Error
</artwork>
                  </figure>
                  <t>For example, if the dynamic table is 100 bytes, then the Required Insert Count will be encoded modulo 6. If a decoder has received 10 inserts, then an encoded value of 4 indicates that the Required Insert Count is 9 for the field section.</t>
               </section>
               <section anchor="base" title="Base">
                  <t>The Base is used to resolve references in the dynamic table as described in <xref target="relative-indexing"/>.</t>
                  <t>To save space, the Base is encoded relative to the Required Insert Count using a one-bit sign (‘S’) and the Delta Base value. A sign bit of 0 indicates that the Base is greater than or equal to the value of the Required Insert Count; the decoder adds the value of Delta Base to the Required Insert Count to determine the value of the Base. A sign bit of 1 indicates that the Base is less than the Required Insert Count; the decoder subtracts the value of Delta Base from the Required Insert Count and also subtracts one to determine the value of the Base. That is:</t>
                  <figure>
                     <artwork>
   if S == 0:
      Base = ReqInsertCount + DeltaBase
   else:
      Base = ReqInsertCount - DeltaBase - 1
</artwork>
                  </figure>
                  <t>A single-pass encoder determines the Base before encoding a field section. If the encoder inserted entries in the dynamic table while encoding the field section and is referencing them, Required Insert Count will be greater than the Base, so the encoded difference is negative and the sign bit is set to 1. If the field section was not encoded using representations that reference the most recent entry in the table and did not insert any new entries, the Base will be greater than the Required Insert Count, 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 field section might set Base to the value of Required Insert Count. In such case, both the sign bit and the Delta Base will be set to zero.</t>
                  <t>A field section that was encoded without references to the dynamic table can use any value for the Base; setting Delta Base to zero is one of the most efficient encodings.</t>
                  <t>For example, with a Required Insert Count of 9, a decoder receives an S bit of 1 and a Delta Base of 2. This sets the Base to 6 and enables post-base indexing for three entries. In this example, a relative index of 1 refers to the 5th entry that was added to the table; a post-base index of 1 refers to the 8th entry.</t>
               </section>
            </section>
            <section anchor="indexed-field-line" title="Indexed Field Line">
               <t>An indexed field line representation identifies an entry in the static table, or an entry in the dynamic table with an absolute index less than the value of the Base.</t>
               <figure title="Indexed Field Line">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 1 | T |      Index (6+)       |
+---+---+-----------------------+
</artwork>
               </figure>
               <t>This representation starts with the ‘1’ 1-bit pattern, followed by the ‘T’ bit indicating whether the reference is into the static or dynamic table. The 6-bit prefix integer (<xref target="prefixed-integers"/>) that follows is used to locate the table entry for the field line. When T=1, the number represents the static table index; when T=0, the number is the relative index of the entry in the dynamic table.</t>
            </section>
            <section anchor="indexed-field-line-with-post-base-index"
                     title="Indexed Field Line With Post-Base Index">
               <t>An indexed field line with post-base index representation identifies an entry in the dynamic table with an absolute index greater than or equal to the value of the Base.</t>
               <figure title="Indexed Field Line with Post-Base Index">
                  <artwork type="drawing">
  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 1 |  Index (4+)   |
+---+---+---+---+---------------+
</artwork>
               </figure>
               <t>This representation starts with the ‘0001’ 4-bit pattern. This is followed by the post-base index (<xref target="post-base"/>) of the matching field line, represented as an integer with a 4-bit prefix; see <xref target="prefixed-integers"/>.</t>
            </section>
            <section anchor="literal-name-reference"
                     title="Literal Field Line With Name Reference">
               <t>A literal field line with name reference representation encodes a field line where the field name matches the field name of an entry in the static table, or the field name of an entry in the dynamic table with an absolute index less than the value of the Base.</t>
               <figure title="Literal Field Line With Name Reference">
                  <artwork type="drawing">
     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 | N | T |Name Index (4+)|
   +---+---+---+---+---------------+
   | H |     Value Length (7+)     |
   +---+---------------------------+
   |  Value String (Length bytes)  |
   +-------------------------------+
</artwork>
               </figure>
               <t>This representation starts with the ‘01’ two-bit pattern. The following bit, ‘N’, indicates whether an intermediary is permitted to add this field line to the dynamic table on subsequent hops. When the ‘N’ bit is set, the encoded field line MUST always be encoded with a literal representation. In particular, when a peer sends a field line that it received represented as a literal field line with the ‘N’ bit set, it MUST use a literal representation to forward this field line. This bit is intended for protecting field values that are not to be put at risk by compressing them; see <xref target="security-considerations"/> for more details.</t>
               <t>The fourth (‘T’) bit indicates whether the reference is to the static or dynamic table. The 4-bit prefix integer (<xref target="prefixed-integers"/>) that follows is used to locate the table entry for the field name. When T=1, the number represents the static table index; when T=0, the number is the relative index of the entry in the dynamic table.</t>
               <t>Only the field name is taken from the dynamic table entry; the field value is encoded as an 8-bit prefix string literal; see <xref target="string-literals"/>.</t>
            </section>
            <section anchor="literal-field-line-with-post-base-name-reference"
                     title="Literal Field Line With Post-Base Name Reference">
               <t>A literal field line with post-base name reference representation encodes a field line where the field name matches the field name of a dynamic table entry with an absolute index greater than or equal to the value of the Base.</t>
               <figure title="Literal Field Line 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>
               <t>This representation starts with the ‘0000’ four-bit pattern. The fifth bit is the ‘N’ bit as described in <xref target="literal-name-reference"/>. This is followed by a post-base index of the dynamic table entry (<xref target="post-base"/>) encoded as an integer with a 3-bit prefix; see <xref target="prefixed-integers"/>.</t>
               <t>Only the field name is taken from the dynamic table entry; the field value is encoded as an 8-bit prefix string literal; see <xref target="string-literals"/>.</t>
            </section>
            <section anchor="literal-field-line-with-literal-name"
                     title="Literal Field Line With Literal Name">
               <t>The literal field line with literal name representation encodes a field name and a field value as string literals.</t>
               <figure title="Literal Field Line With Literal Name">
                  <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>
               <t>This representation begins with the ‘001’ three-bit pattern. The fourth bit is the ‘N’ bit as described in <xref target="literal-name-reference"/>. The name follows, represented as a 4-bit prefix string literal, then the value, represented as an 8-bit prefix string literal; see <xref target="string-literals"/>.</t>
            </section>
         </section>
      </section>
      <section anchor="configuration" title="Configuration">
         <t>QPACK defines two settings for the HTTP/3 SETTINGS frame:</t>
         <t>
            <list style="hanging">
               <t hangText="SETTINGS_QPACK_MAX_TABLE_CAPACITY (0x1):">The default value is zero. See <xref target="header-table-dynamic"/> for usage. This is the equivalent of the SETTINGS_HEADER_TABLE_SIZE from HTTP/2.</t>
               <t hangText="SETTINGS_QPACK_BLOCKED_STREAMS (0x7):">The default value is zero. See <xref target="blocked-streams"/>.</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 that prevent the stream or connection from continuing:</t>
         <t>
            <list style="hanging">
               <t hangText="QPACK_DECOMPRESSION_FAILED (0x200):">The decoder failed to interpret an encoded field section and is not able to continue decoding that field section.</t>
               <t hangText="QPACK_ENCODER_STREAM_ERROR (0x201):">The decoder failed to interpret an encoder instruction received on the encoder stream.</t>
               <t hangText="QPACK_DECODER_STREAM_ERROR (0x202):">The encoder failed to interpret a decoder instruction received on the decoder stream.</t>
            </list>
         </t>
      </section>
      <section anchor="security-considerations" title="Security Considerations"><!-- lifted from HPACK with minimal modifications for QPACK -->
         <t>This section describes potential areas of security concern with QPACK:</t>
         <t>
            <list style="symbols">
               <t>Use of compression as a length-based oracle for verifying guesses about secrets that are compressed into a shared compression context.</t>
               <t>Denial of service resulting from exhausting processing or memory capacity at a decoder.</t>
            </list>
         </t>
         <section anchor="probing-dynamic-table-state"
                  title="Probing Dynamic Table State">
            <t>QPACK reduces the encoded size of field sections by exploiting the redundancy inherent in protocols like HTTP. The ultimate goal of this is to reduce the amount of data that is required to send HTTP requests or responses.</t>
            <t>The compression context used to encode header and trailer fields can be probed by an attacker who can both define fields to be encoded and transmitted and observe the length of those fields once they are encoded. When an attacker can do both, they can adaptively modify requests in order to confirm guesses about the dynamic table state. If a guess is compressed into a shorter length, the attacker can observe the encoded length and infer that the guess was correct.</t>
            <t>This is possible even over the Transport Layer Security Protocol (TLS, see <xref target="TLS"/>), because while TLS provides confidentiality protection for content, it only provides a limited amount of protection for the length of that content.</t>
            <t>
               <list style="hanging">
                  <t hangText="Note:">Padding schemes only provide limited protection against an attacker with these capabilities, potentially only forcing an increased number of guesses to learn the length associated with a given guess. Padding schemes also work directly against compression by increasing the number of bits that are transmitted.</t>
               </list>
            </t>
            <t>Attacks like CRIME (<xref target="CRIME"/>) demonstrated the existence of these general attacker capabilities. The specific attack exploited the fact that DEFLATE (<xref target="RFC1951"/>) removes redundancy based on prefix matching. This permitted the attacker to confirm guesses a character at a time, reducing an exponential-time attack into a linear-time attack.</t>
         </section>
         <section anchor="applicability-to-qpack-and-http"
                  title="Applicability to QPACK and HTTP">
            <t>QPACK mitigates but does not completely prevent attacks modeled on CRIME (<xref target="CRIME"/>) by forcing a guess to match an entire field line, rather than individual characters. An attacker can only learn whether a guess is correct or not, so is reduced to a brute force guess for the field values associated with a given field name.</t>
            <t>The viability of recovering specific field values therefore depends on the entropy of values. As a result, values with high entropy are unlikely to be recovered successfully. However, values with low entropy remain vulnerable.</t>
            <t>Attacks of this nature are possible any time that two mutually distrustful entities control requests or responses that are placed onto a single HTTP/3 connection. If the shared QPACK compressor permits one entity to add entries to the dynamic table, and the other to access those entries, then the state of the table can be learned.</t>
            <t>Having requests or responses from mutually distrustful entities occurs when an intermediary either:</t>
            <t>
               <list style="symbols">
                  <t>sends requests from multiple clients on a single connection toward an origin server, or</t>
                  <t>takes responses from multiple origin servers and places them on a shared connection toward a client.</t>
               </list>
            </t>
            <t>Web browsers also need to assume that requests made on the same connection by different web origins (<xref target="RFC6454"/>) are made by mutually distrustful entities.</t>
         </section>
         <section anchor="mitigation" title="Mitigation">
            <t>Users of HTTP that require confidentiality for header or trailer fields can use values with entropy sufficient to make guessing infeasible. However, this is impractical as a general solution because it forces all users of HTTP to take steps to mitigate attacks. It would impose new constraints on how HTTP is used.</t>
            <t>Rather than impose constraints on users of HTTP, an implementation of QPACK can instead constrain how compression is applied in order to limit the potential for dynamic table probing.</t>
            <t>An ideal solution segregates access to the dynamic table based on the entity that is constructing the message. Field values that are added to the table are attributed to an entity, and only the entity that created a particular value can extract that value.</t>
            <t>To improve compression performance of this option, certain entries might be tagged as being public. For example, a web browser might make the values of the Accept-Encoding header field available in all requests.</t>
            <t>An encoder without good knowledge of the provenance of field values might instead introduce a penalty for many field lines with the same field name and different values. This penalty could cause a large number of attempts to guess a field value to result in the field not being compared to the dynamic table entries in future messages, effectively preventing further guesses.</t>
            <t>
               <list style="hanging">
                  <t hangText="Note:">Simply removing entries corresponding to the field from the dynamic table can be ineffectual if the attacker has a reliable way of causing values to be reinstalled. For example, a request to load an image in a web browser typically includes the Cookie header field (a potentially highly valued target for this sort of attack), and web sites can easily force an image to be loaded, thereby refreshing the entry in the dynamic table.</t>
               </list>
            </t>
            <t>This response might be made inversely proportional to the length of the field value. Disabling access to the dynamic table for a given field name might occur for shorter values more quickly or with higher probability than for longer values.</t>
         </section>
         <section anchor="never-indexed-literals" title="Never-Indexed Literals">
            <t>Implementations can also choose to protect sensitive fields by not compressing them and instead encoding their value as literals.</t>
            <t>Refusing to insert a field line into the dynamic table is only effective if doing so is avoided on all hops. The never-indexed literal bit (see <xref target="literal-name-reference"/>) can be used to signal to intermediaries that a particular value was intentionally sent as a literal.</t>
            <t>An intermediary MUST NOT re-encode a value that uses a literal representation with the ‘N’ bit set with another representation that would index it. If QPACK is used for re-encoding, a literal representation with the ‘N’ bit set MUST be used. If HPACK is used for re-encoding, the never-indexed literal representation (see <xref target="RFC7541" x:fmt="of" x:sec="6.2.3"/>) MUST be used.</t>
            <t>The choice to mark that a field value should never be indexed depends on several factors. Since QPACK does not protect against guessing an entire field value, short or low-entropy values are more readily recovered by an adversary. Therefore, an encoder might choose not to index values with low entropy.</t>
            <t>An encoder might also choose not to index values for fields that are considered to be highly valuable or sensitive to recovery, such as the Cookie or Authorization header fields.</t>
            <t>On the contrary, an encoder might prefer indexing values for fields that have little or no value if they were exposed. For instance, a User-Agent header field does not commonly vary between requests and is sent to any server. In that case, confirmation that a particular User-Agent value has been used provides little value.</t>
            <t>Note that these criteria for deciding to use a never-indexed literal representation will evolve over time as new attacks are discovered.</t>
         </section>
         <section anchor="static-huffman-encoding" title="Static Huffman Encoding">
            <t>There is no currently known attack against a static Huffman encoding. A study has shown that using a static Huffman encoding table created an information leakage, however this same study concluded that an attacker could not take advantage of this information leakage to recover any meaningful amount of information (see <xref target="PETAL"/>).</t>
         </section>
         <section anchor="memory-consumption" title="Memory Consumption">
            <t>An attacker can try to cause an endpoint to exhaust its memory. QPACK is designed to limit both the peak and stable amounts of memory allocated by an endpoint.</t>
            <t>The amount of memory used by the encoder is limited by the protocol using QPACK through the definition of the maximum size of the dynamic table, and the maximum number of blocking streams. In HTTP/3, these values are controlled by the decoder through the settings parameters SETTINGS_QPACK_MAX_TABLE_CAPACITY and SETTINGS_QPACK_BLOCKED_STREAMS, respectively (see <xref target="maximum-dynamic-table-capacity"/> and <xref target="blocked-streams"/>). The limit on the size of the dynamic table takes into account the size of the data stored in the dynamic table, plus a small allowance for overhead. The limit on the number of blocked streams is only a proxy for the maximum amount of memory required by the decoder. The actual maximum amount of memory will depend on how much memory the decoder uses to track each blocked stream.</t>
            <t>A decoder can limit the amount of state memory used for the dynamic table by setting an appropriate value for the maximum size of the dynamic table. In HTTP/3, this is realized by setting an appropriate value for the SETTINGS_QPACK_MAX_TABLE_CAPACITY parameter. An encoder can limit the amount of state memory it uses by signaling a lower dynamic table size than the decoder allows (see <xref target="eviction"/>).</t>
            <t>A decoder can limit the amount of state memory used for blocked streams by setting an appropriate value for the maximum number of blocked streams. In HTTP/3, this is realized by setting an appropriate value for the QPACK_BLOCKED_STREAMS parameter. Streams which risk becoming blocked consume no additional state memory on the encoder.</t>
            <t>An encoder allocates memory to track all dynamic table references in unacknowledged field sections. An implementation can directly limit the amount of state memory by only using as many references to the dynamic table as it wishes to track; no signaling to the decoder is required. However, limiting references to the dynamic table will reduce compression effectiveness.</t>
            <t>The amount of temporary memory consumed by an encoder or decoder can be limited by processing field lines sequentially. A decoder implementation does not need to retain a complete list of field lines while decoding a field section. An encoder implementation does not need to retain a complete list of field lines while encoding a field section if it is using a single-pass algorithm. Note that it might be necessary for an application to retain a complete list of field lines for other reasons; even if QPACK does not force this to occur, application constraints might make this necessary.</t>
            <t>While the negotiated limit on the dynamic table size accounts for much of the memory that can be consumed by a QPACK implementation, data that cannot be immediately sent due to flow control is not affected by this limit. Implementations should limit the size of unsent data, especially on the decoder stream where flexibility to choose what to send is limited. Possible responses to an excess of unsent data might include limiting the ability of the peer to open new streams, reading only from the encoder stream, or closing the connection.</t>
         </section>
         <section anchor="implementation-limits" title="Implementation Limits">
            <t>An implementation of QPACK needs to ensure that large values for integers, long encoding for integers, or long string literals do not create security weaknesses.</t>
            <t>An implementation has to set a limit for the values it accepts for integers, as well as for the encoded length; see <xref target="prefixed-integers"/>. In the same way, it has to set a limit to the length it accepts for string literals; see <xref target="string-literals"/>.</t>
         </section>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <section anchor="settings-registration" title="Settings Registration">
            <t>This document specifies two settings. The entries in the following table are registered in the “HTTP/3 Settings” registry established in <xref target="HTTP3"/>.</t>
            <texttable>
               <ttcol align="left">Setting Name</ttcol>
               <ttcol align="center">Code</ttcol>
               <ttcol align="left">Specification</ttcol>
               <ttcol align="left">Default</ttcol>
               <c>QPACK_MAX_TABLE_CAPACITY</c>
               <c>0x1</c>
               <c>
                  <xref target="configuration"/>
               </c>
               <c>0</c>
               <c>QPACK_BLOCKED_STREAMS</c>
               <c>0x7</c>
               <c>
                  <xref target="configuration"/>
               </c>
               <c>0</c>
            </texttable>
         </section>
         <section anchor="stream-type-registration" title="Stream Type Registration">
            <t>This document specifies two stream types. The entries in the following table are registered in the “HTTP/3 Stream Type” registry established in <xref target="HTTP3"/>.</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>0x02</c>
               <c>
                  <xref target="enc-dec-stream-def"/>
               </c>
               <c>Both</c>
               <c>QPACK Decoder Stream</c>
               <c>0x03</c>
               <c>
                  <xref target="enc-dec-stream-def"/>
               </c>
               <c>Both</c>
            </texttable>
         </section>
         <section anchor="error-code-registration" title="Error Code Registration">
            <t>This document specifies three error codes. The entries in the following table are registered 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>QPACK_DECOMPRESSION_FAILED</c>
               <c>0x200</c>
               <c>Decoding of a field section failed</c>
               <c>
                  <xref target="error-handling"/>
               </c>
               <c>QPACK_ENCODER_STREAM_ERROR</c>
               <c>0x201</c>
               <c>Error on the encoder stream</c>
               <c>
                  <xref target="error-handling"/>
               </c>
               <c>QPACK_DECODER_STREAM_ERROR</c>
               <c>0x202</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-31"/>
            <x:source basename="draft-ietf-quic-http-31"
                      href="draft-ietf-quic-http-31.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-31"/>
            <x:source basename="draft-ietf-quic-transport-31"
                      href="draft-ietf-quic-transport-31.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>
         <reference anchor="SEMANTICS">
            <front>
               <title>HTTP Semantics</title>
               <author fullname="Roy Fielding" initials="R" surname="Fielding"/>
               <author fullname="Mark Nottingham" initials="M" surname="Nottingham"/>
               <author fullname="Julian Reschke" initials="J" surname="Reschke"/>
               <date day="27" month="August" year="2020"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-semantics-11"/>
            <x:source basename="draft-ietf-httpbis-semantics-11"
                      href="draft-ietf-httpbis-semantics-11.xml"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="CRIME"
                    target="http://en.wikipedia.org/w/index.php?title=CRIME&amp;oldid=660948120">
            <front>
               <title>CRIME</title>
               <author>
                  <organization>Wikipedia</organization>
               </author>
               <date month="May" year="2015"/>
            </front>
         </reference>
         <reference anchor="PETAL"
                    target="http://www.pdl.cmu.edu/PDL-FTP/associated/CMU-PDL-13-106.pdf">
            <front>
               <title>PETAL: Preset Encoding Table Information Leakage</title>
               <author fullname="Jiaqi Tan" initials="J." surname="Tan"/>
               <author fullname="Jayvardhan Nahata" initials="J." surname="Nahata"/>
               <date month="April" year="2013"/>
            </front>
         </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>
         <reference anchor="TLS">
            <front>
               <title>The Transport Layer Security (TLS) Protocol Version 1.3</title>
               <author fullname="E. Rescorla" initials="E." surname="Rescorla"/>
               <date month="August" year="2018"/>
            </front>
            <seriesInfo name="RFC" value="8446"/>
            <seriesInfo name="DOI" value="10.17487/RFC8446"/>
         </reference>
         <reference anchor="RFC1951">
            <front>
               <title>DEFLATE Compressed Data Format Specification version 1.3</title>
               <author fullname="P. Deutsch" initials="P." surname="Deutsch"/>
               <date month="May" year="1996"/>
            </front>
            <seriesInfo name="RFC" value="1951"/>
            <seriesInfo name="DOI" value="10.17487/RFC1951"/>
         </reference>
         <reference anchor="RFC6454">
            <front>
               <title>The Web Origin Concept</title>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="December" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6454"/>
            <seriesInfo name="DOI" value="10.17487/RFC6454"/>
         </reference>
      </references>
      <section anchor="static-table" title="Static Table">
         <t>This table was generated by analyzing actual Internet traffic in 2018 and including the most common header fields, after filtering out some unsupported and non-standard values. Due to this methodology, some of the entries may be inconsistent or appear multiple times with similar but not identical values. The order of the entries is optimized to encode the most common header fields with the smallest number of bytes.</t>
         <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="encoding-and-decoding-examples"
               title="Encoding and Decoding Examples">
         <t>The following examples represent a series of exchanges between an encoder and a decoder. The exchanges are designed to exercise most QPACK instructions, and highlight potentially common patterns and their impact on dynamic table state. The encoder sends three encoded field sections containing one field line each, as wells as two speculative inserts that are not referenced.</t>
         <t>The state of the encoder’s dynamic table is shown, along with its current size. Each entry is shown with the Absolute Index of the entry (Abs), the current number of outstanding encoded field sections with references to that entry (Ref), along with the name and value. Entries above the ‘acknowledged’ line have been acknowledged by the decoder.</t>
         <section anchor="literal-field-line-with-name-reference"
                  title="Literal Field Line With Name Reference">
            <t>The encoder sends an encoded field section containing a literal representation of a field with a static name reference.</t>
            <figure>
               <artwork>
Data                | Interpretation
                             | Encoder's Dynamic Table

Stream: 0
0000                | Required Insert Count = 0, Base = 0
510b 2f69 6e64 6578 | Literal Field Line with Name Reference
2e68 746d 6c        |  Static Table, Index=1
                    |  (:path=/index.html)

                              Abs Ref Name        Value
                              ^-- acknowledged --^
                              Size=0
</artwork>
            </figure>
         </section>
         <section anchor="dynamic-table" title="Dynamic Table">
            <t>The encoder sets the dynamic table capacity, inserts a header with a dynamic name reference, then sends a potentially blocking, encoded field section referencing this new entry. The decoder acknowledges processing the encoded field section, which implicitly acknowledges all dynamic table insertions up to the Required Insert Count.</t>
            <figure>
               <artwork>
Stream: Encoder
3fbd01              | Set Dynamic Table Capacity=220
c00f 7777 772e 6578 | Insert With Name Reference
616d 706c 652e 636f | Static Table, Index=0
6d                  |  (:authority=www.example.com)
c10c 2f73 616d 706c | Insert With Name Reference
652f 7061 7468      |  Static Table, Index=1
                    |  (:path=/sample/path)

                              Abs Ref Name        Value
                              ^-- acknowledged --^
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                              Size=106

Stream: 4
0381                | Required Insert Count = 2, Base = 0
10                  | Indexed Field Line With Post-Base Index
                    |  Absolute Index = Base(0) + Index(0) + 1 = 1
                    |  (:authority=www.example.com)
11                  | Indexed Field Line With Post-Base Index
                    |  Absolute Index = Base(0) + Index(1) + 1 = 2
                    |  (:path=/sample/path)

                              Abs Ref Name        Value
                              ^-- acknowledged --^
                               1   1  :authority  www.example.com
                               2   1  :path       /sample/path
                              Size=106

Stream: Decoder
84                  | Section Acknowledgement (stream=4)

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                              ^-- acknowledged --^
                              Size=106
</artwork>
            </figure>
         </section>
         <section anchor="speculative-insert" title="Speculative Insert">
            <t>The encoder inserts a header into the dynamic table with a literal name. The decoder acknowledges receipt of the entry. The encoder does not send any encoded field sections.</t>
            <figure>
               <artwork>
Stream: Encoder
4a63 7573 746f 6d2d | Insert With Literal Name
6b65 790c 6375 7374 |  (custom-key=custom-value)
6f6d 2d76 616c 7565 |

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                              ^-- acknowledged --^
                               3   0  custom-key  custom-value
                              Size=160

Stream: Decoder
01                  | Insert Count Increment (1)

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                               3   0  custom-key  custom-value
                              ^-- acknowledged --^
                              Size=160

</artwork>
            </figure>
         </section>
         <section anchor="duplicate-instruction-stream-cancellation"
                  title="Duplicate Instruction, Stream Cancellation">
            <t>The encoder duplicates an existing entry in the dynamic table, then sends an encoded field section referencing the dynamic table entries including the duplicated entry. The decoder notifies the encoder that the encoded field section was not processed by sending a stream cancellation.</t>
            <figure>
               <artwork>
Stream: Encoder
02                  | Duplicate (Relative Index=2)

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                               3   0  custom-key  custom-value
                              ^-- acknowledged --^
                               4   0  :authority  www.example.com
                              Size=217

Stream: 8
0500                | Required Insert Count = 4, Base = 4
80                  | Indexed Field Line, Dynamic Table
                    |  Absolute Index = Base(4) - Index(0) = 4
                    |  (:authority=www.example.com)
c1                  | Indexed Field Line, Static Table Index = 1
                    |  (:path=/)
81                  | Indexed Field Line, Dynamic Table
                    |  Absolute Index = Base(4) - Index(1) = 3
                    |  (custom-key=custom-value)

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                               3   1  custom-key  custom-value
                              ^-- acknowledged --^
                               4   1  :authority  www.example.com
                              Size=217

Stream: Decoder
48                  | Stream Cancellation (Stream=8)

                              Abs Ref Name        Value
                               1   0  :authority  www.example.com
                               2   0  :path       /sample/path
                               3   0  custom-key  custom-value
                              ^-- acknowledged --^
                               4   0  :authority  www.example.com
                              Size=215

</artwork>
            </figure>
         </section>
         <section anchor="dynamic-table-insert-eviction"
                  title="Dynamic Table Insert, Eviction">
            <t>The encoder inserts another header into the dynamic table, which evicts the oldest entry. The encoder does not send any encoded field sections.</t>
            <figure>
               <artwork>
Stream: Encoder
810d 6375 7374 6f6d | Insert With Name Reference
2d76 616c 7565 32   |  Dynamic Table, Absolute Index=2
                    |  (custom-key=custom-value2)

                              Abs Ref Name        Value
                               2   0  :path       /sample/path
                               3   0  custom-key  custom-value
                              ^-- acknowledged --^
                               4   0  :authority  www.example.com
                               5   0  custom-key  custom-value2
                              Size=215
</artwork>
            </figure>
         </section>
      </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, available encoder stream flow control and reference tracking.</t>
         <figure>
            <artwork>
base = dynamicTable.getInsertCount()
requiredInsertCount = 0
for line in field_lines:
  staticIndex = staticTable.findIndex(line)
  if staticIndex is not None:
    encodeIndexReference(streamBuffer, staticIndex)
    continue

  dynamicIndex = dynamicTable.findIndex(line)
  if dynamicIndex is None:
    # No matching entry.  Either insert+index or encode literal
    staticNameIndex = staticTable.findName(line.name)
    if staticNameIndex is None:
       dynamicNameIndex = dynamicTable.findName(line.name)

    if shouldIndex(line) and dynamicTable.canIndex(line):
      encodeInsert(encoderBuffer, staticNameIndex,
                   dynamicNameIndex, line)
      dynamicIndex = dynamicTable.add(line)

  if dynamicIndex is None:
    # Could not index it, literal
    if dynamicNameIndex is not None:
      # Encode literal with dynamic name, possibly above base
      encodeDynamicLiteral(streamBuffer, dynamicNameIndex,
                           base, line)
      requiredInsertCount = max(requiredInsertCount,
                                dynamicNameIndex)
    else:
      # Encodes a literal with a static name or literal name
      encodeLiteral(streamBuffer, staticNameIndex, line)
  else:
    # Dynamic index reference
    assert(dynamicIndex is not None)
    requiredInsertCount = max(requiredInsertCount, dynamicIndex)
    # Encode dynamicIndex, possibly above base
    encodeDynamicIndexReference(streamBuffer, dynamicIndex, base)

# encode the prefix
if requiredInsertCount == 0:
  encodeIndexReference(prefixBuffer, 0, 0, 8)
  encodeIndexReference(prefixBuffer, 0, 0, 7)
else:
  wireRIC = (
    requiredInsertCount
    % (2 * getMaxEntries(maxTableCapacity))
  ) + 1;
  encodeInteger(prefixBuffer, 0x00, wireRIC, 8)
  if base &gt;= requiredInsertCount:
    encodeInteger(prefixBuffer, 0, base - requiredInsertCount, 7)
  else:
    encodeInteger(prefixBuffer, 0x80,
                  requiredInsertCount  - base - 1, 7)

return encoderBuffer, 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-17"
                  title="Since draft-ietf-quic-qpack-17">
            <t>Editorial changes only</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-16"
                  title="Since draft-ietf-quic-qpack-16">
            <t>Editorial changes only</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-15"
                  title="Since draft-ietf-quic-qpack-15">
            <t>No changes</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-14"
                  title="Since draft-ietf-quic-qpack-14">
            <t>Added security considerations</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-13"
                  title="Since draft-ietf-quic-qpack-13">
            <t>No changes</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-12"
                  title="Since draft-ietf-quic-qpack-12">
            <t>Editorial changes only</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-11"
                  title="Since draft-ietf-quic-qpack-11">
            <t>Editorial changes only</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-10"
                  title="Since draft-ietf-quic-qpack-10">
            <t>Editorial changes only</t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-09"
                  title="Since draft-ietf-quic-qpack-09">
            <t>
               <list style="symbols">
                  <t>Decoders MUST emit Header Acknowledgements (#2939)</t>
                  <t>Updated error code for multiple encoder or decoder streams (#2970)</t>
                  <t>Added explicit defaults for new SETTINGS (#2974)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-08"
                  title="Since draft-ietf-quic-qpack-08">
            <t>
               <list style="symbols">
                  <t>Endpoints are permitted to create encoder and decoder streams even if they can’t use them (#2100, #2529)</t>
                  <t>Maximum values for settings removed (#2766, #2767)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-06"
                  title="Since draft-ietf-quic-qpack-06">
            <t>
               <list style="symbols">
                  <t>Clarify initial dynamic table capacity maximums (#2276, #2330, #2330)</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-quic-qpack-05"
                  title="Since draft-ietf-quic-qpack-05">
            <t>
               <list style="symbols">
                  <t>Introduced the terms dynamic table capacity and maximum dynamic table capacity.</t>
                  <t>Renamed SETTINGS_HEADER_TABLE_SIZE to SETTINGS_QPACK_MAX_TABLE_CAPACITY.</t>
               </list>
            </t>
         </section>
         <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>The IETF QUIC Working Group received an enormous amount of support from many people.</t>
         <t>The compression design team did substantial work exploring the problem space and influencing the initial draft. The contributions of design team members Roberto Peon, Martin Thomson, and Dmitri Tikhonov are gratefully acknowledged.</t>
         <t>The following people also provided substantial contributions to this document:</t>
         <t>
            <list style="symbols">
               <t>Bence Béky</t>
               <t>Alessandro Ghedini</t>
               <t>Ryan Hamilton</t>
               <t>Robin Marx</t>
               <t>Patrick McManus</t>
               <t>
                  <contact asciiFullname="Kazuho Oku" fullname="奥 一穂"/>
               </t>
               <t>Lucas Pardue</t>
               <t>Biren Roy</t>
               <t>Ian Swett</t>
            </list>
         </t>
         <t>This draft draws heavily on the text of <xref target="RFC7541"/>. The indirect input of those authors is also gratefully acknowledged.</t>
         <t>Buck’s contribution was supported by Google during his employment there.</t>
         <t>A portion of Mike’s contribution was supported by Microsoft during his employment there.</t>
      </section>
   </back>
</rfc>
