QUIC                                                           C. Krasic
Internet-Draft                                                   Netflix
Intended status: Standards Track                               M. Bishop
Expires: April 6, June 7, 2019                                Akamai Technologies
                                                        A. Frindell, Ed.
                                                                Facebook
                                                        October 03,
                                                       December 04, 2018

              QPACK: Header Compression for HTTP over QUIC
                        draft-ietf-quic-qpack-03
                        draft-ietf-quic-qpack-04

Abstract

   This specification defines QPACK, a compression format for
   efficiently representing HTTP header fields, to be used in HTTP/QUIC. HTTP/3.
   This is a variation of HPACK header compression that seeks to reduce
   head-of-line blocking.

Note to Readers

   Discussion of this draft takes place on the QUIC working group
   mailing list (quic@ietf.org), which is archived at
   https://mailarchive.ietf.org/arch/search/?email_list=quic [1].

   Working Group information can be found at https://github.com/quicwg
   [2]; source code and issues list for this draft can be found at
   https://github.com/quicwg/base-drafts/labels/-qpack [3].

Status of This Memo

   This Internet-Draft is submitted in full conformance with the
   provisions of BCP 78 and BCP 79.

   Internet-Drafts are working documents of the Internet Engineering
   Task Force (IETF).  Note that other groups may also distribute
   working documents as Internet-Drafts.  The list of current Internet-
   Drafts is at https://datatracker.ietf.org/drafts/current/.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time.  It is inappropriate to use Internet-Drafts as reference
   material or to cite them other than as "work in progress."

   This Internet-Draft will expire on April 6, June 7, 2019.

Copyright Notice

   Copyright (c) 2018 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (https://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   3
   2.  Header Tables
     1.1.  Conventions and Definitions . . . . . . . . . . . . . . .   4
     1.2.  Notational Conventions  . . . . . . . . .   4
     2.1.  Static Table . . . . . . . .   4
   2.  Compression Process Overview  . . . . . . . . . . . . . .   4
     2.2.  Dynamic Table . .   5
     2.1.  Encoder . . . . . . . . . . . . . . . . . . . .   4
       2.2.1.  Maximum Table Size . . . . .   5
       2.1.1.  Reference Tracking  . . . . . . . . . . . .   5
       2.2.2.  Calculating Table Size . . . . .   6
       2.1.2.  Blocked Dynamic Table Insertions  . . . . . . . . . .   6
       2.2.3.  Absolute Indexing
       2.1.3.  Avoiding Head-of-Line Blocking  . . . . . . . . . . .   7
       2.1.4.  Largest Known Received  . . . . . . .   6
       2.2.4.  Relative Indexing . . . . . . . .   7
     2.2.  Decoder . . . . . . . . . .   6
       2.2.5.  Post-Base Indexing . . . . . . . . . . . . . . .   8
       2.2.1.  State Synchronization . .   7
     2.3.  Avoiding Head-of-Line Blocking in HTTP/QUIC . . . . . . .   8
       2.3.1.  State Synchronization . . . . . . .   8
       2.2.2.  Blocked Decoding  . . . . . . . . .   9
   3.  Conventions and Definitions . . . . . . . . .   9
   3.  Header Tables . . . . . . . .  10
     3.1.  Notational Conventions . . . . . . . . . . . . . . . .   9
     3.1.  Static Table  .  10
   4.  Configuration . . . . . . . . . . . . . . . . . . . . .   9
     3.2.  Dynamic Table . . .  10
   5.  Wire Format . . . . . . . . . . . . . . . . . . .   9
       3.2.1.  Maximum Table Size  . . . . . .  11
     5.1.  Primitives . . . . . . . . . . .  10
       3.2.2.  Calculating Table Size  . . . . . . . . . . . .  11
       5.1.1.  Prefixed Integers . . .  10
       3.2.3.  Absolute Indexing . . . . . . . . . . . . . . .  11
       5.1.2.  String Literals . . .  11
       3.2.4.  Relative Indexing . . . . . . . . . . . . . . . . .  11
     5.2.  QPACK Encoder Stream .  11
       3.2.5.  Post-Base Indexing  . . . . . . . . . . . . . . . . .  12
       5.2.1.  Insert With Name Reference
       3.2.6.  Invalid References  . . . . . . . . . . . . .  12
       5.2.2.  Insert Without Name Reference . . . .  12
   4.  Wire Format . . . . . . . .  13
       5.2.3.  Duplicate . . . . . . . . . . . . . . . . .  13
     4.1.  Primitives  . . . . .  13
       5.2.4.  Dynamic Table Size Update . . . . . . . . . . . . . .  14
     5.3.  QPACK Decoder Stream . . . .  13
       4.1.1.  Prefixed Integers . . . . . . . . . . . . . .  14
       5.3.1.  Table State Synchronize . . . .  13
       4.1.2.  String Literals . . . . . . . . . . .  14
       5.3.2.  Header Acknowledgement . . . . . . . .  13
     4.2.  Stream Types  . . . . . . .  15
       5.3.3.  Stream Cancellation . . . . . . . . . . . . . . .  13
     4.3.  Encoder Stream  . .  16
     5.4.  Request and Push Streams . . . . . . . . . . . . . . . .  17
       5.4.1.  Header Data Prefix . . .  14
       4.3.1.  Insert With Name Reference  . . . . . . . . . . . . .  14
       4.3.2.  Insert Without Name Reference .  17
       5.4.2.  Instructions . . . . . . . . . . .  15
       4.3.3.  Duplicate . . . . . . . . .  18
   6.  Error Handling . . . . . . . . . . . . .  15
       4.3.4.  Dynamic Table Size Update . . . . . . . . . .  21
   7.  Encoding Strategies . . . .  16

     4.4.  Decoder Stream  . . . . . . . . . . . . . . . . .  22
     7.1.  Single Pass Encoding . . . .  16
       4.4.1.  Table State Synchronize . . . . . . . . . . . . . .  22
     7.2.  Preventing Eviction Races .  16
       4.4.2.  Header Acknowledgement  . . . . . . . . . . . . . . .  22
     7.3.  Reference Tracking  17
       4.4.3.  Stream Cancellation . . . . . . . . . . . . . . . . .  18
     4.5.  Request and Push Streams  . .  22
       7.3.1.  Blocked Dynamic Table Insertions . . . . . . . . . .  22
       7.3.2.  Blocked Decoding . . . .  18
       4.5.1.  Header Data Prefix  . . . . . . . . . . . . . .  23
     7.4.  Speculative table updates . . .  18
       4.5.2.  Indexed Header Field  . . . . . . . . . . . . . . . .  20
       4.5.3.  Indexed Header Field With Post-Base Index . . . . . .  21
       4.5.4.  Literal Header Field With Name Reference  . . . . . .  21
       4.5.5.  Literal Header Field With Post-Base Name Reference  .  22
       4.5.6.  Literal Header Field Without Name Reference . . . . .  22
   5.  Configuration . . . . . . . . . . . . . . . . . . . . . . . .  23
     7.5.  Sample One Pass Encoding Algorithm
   6.  Error Handling  . . . . . . . . . . .  24
   8. . . . . . . . . . . . .  23
   7.  Security Considerations . . . . . . . . . . . . . . . . . . .  26
   9.  24
   8.  IANA Considerations . . . . . . . . . . . . . . . . . . . . .  26
     9.1.  24
     8.1.  Settings Registration . . . . . . . . . . . . . . . . . .  26
     9.2.  24
     8.2.  Stream Type Registration  . . . . . . . . . . . . . . . .  26
     9.3.  24
     8.3.  Error Code Registration . . . . . . . . . . . . . . . . .  26
   10.  24
   9.  References  . . . . . . . . . . . . . . . . . . . . . . . . .  27
     10.1.  25
     9.1.  Normative References  . . . . . . . . . . . . . . . . . .  27
     10.2.  25
     9.2.  Informative References  . . . . . . . . . . . . . . . . .  28
     10.3.  26
     9.3.  URIs  . . . . . . . . . . . . . . . . . . . . . . . . . .  28  26
   Appendix A.  Static Table . . . . . . . . . . . . . . . . . . . .  28  26
   Appendix B.  Sample One Pass Encoding Algorithm . . . . . . . . .  31
   Appendix C.  Change Log . . . . . . . . . . . . . . . . . . . . .  33
     B.1.
     C.1.  Since draft-ietf-quic-qpack-03  . . . . . . . . . . . . .  33
     C.2.  Since draft-ietf-quic-qpack-02  . . . . . . . . . . . . .  33
     B.2.
     C.3.  Since draft-ietf-quic-qpack-01  . . . . . . . . . . . . .  33
     B.3.
     C.4.  Since draft-ietf-quic-qpack-00  . . . . . . . . . . . . .  33
     B.4.
     C.5.  Since draft-ietf-quic-qcram-00  . . . . . . . . . . . . .  34
   Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . .  34
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  34

1.  Introduction

   The QUIC transport protocol was designed from the outset to support
   HTTP semantics, and its design subsumes many of the features of
   HTTP/2.  HTTP/2 uses HPACK ([RFC7541]) for header compression, but
   QUIC's stream multiplexing comes into some conflict with HPACK.  A
   key goal of the design of QUIC is to improve stream multiplexing
   relative to HTTP/2 by reducing head-of-line blocking.  If HPACK were
   used for HTTP/QUIC, HTTP/3, it would induce head-of-line blocking due to
   built-in built-
   in assumptions of a total ordering across frames on all streams.

   QUIC is described in [QUIC-TRANSPORT].  The HTTP/QUIC HTTP/3 mapping is
   described in [QUIC-HTTP]. [HTTP3].  For a full description of HTTP/2, see
   [RFC7540].  The description of HPACK is [RFC7541].

   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.

   QPACK preserves the ordering of header fields within each header
   list.  An encoder MUST emit header field representations

1.1.  Conventions and Definitions

   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
   "OPTIONAL" in the order this document are to be interpreted as described in BCP
   14 [RFC2119] [RFC8174] when, and only when, they appear in the input header list.  A decoder MUST must emit
   header fields in the order their representations appear all
   capitals, as shown here.

   Definitions of terms that are used in the input this document:

   Header field:  A name-value pair sent as part of an HTTP message.

   Header list:  An ordered collection of header fields associated with
      an HTTP message.  A header list can contain multiple header fields
      with the same name.  It can also contain duplicate header fields.

   Header block:  The compressed representation of a header list.

   Encoder:  An implementation which transforms a header list into a
      header block.

   Decoder:  An implementation which transforms a header block into a
      header list.

   Absolute Index:  A unique index for each entry in the dynamic table.

   Base Index:  An absolute index in a header block from which relative
      indices are made.

   Largest Reference:  The largest absolute index of an entry referenced
      in a header block.

   QPACK is a name, not an acronym.

1.2.  Notational Conventions

   Diagrams use the format described in Section 3.1 of [RFC2360], with
   the following additional conventions:

   x (A)  Indicates that x is A bits long
   x (A+)  Indicates that x uses the prefixed integer encoding defined
      in Section 5.1 of [RFC7541], beginning with an A-bit prefix.

   x ...  Indicates that x is variable-length and extends to the end of
      the region.

2.  Header Tables  Compression Process Overview

   Like HPACK, QPACK uses two tables for associating header fields to
   indices.  The static table (see Section 2.1) 3.1) is predefined and
   contains common header fields (some of them with an empty value).
   The dynamic table (see Section 2.2) 3.2) is built up over the course of
   the connection and can be used by the encoder to index header fields
   repeated
   in the encoded header lists.

   Unlike in HPACK, entries in the

   QPACK static and dynamic tables are
   addressed separately.  The following sections describe how entries instructions appear in
   each table are addressed.

2.1.  Static Table

   The static table consists three different types of streams:

   o  The encoder uses a predefined static list unidirectional stream to modify the state of
      the dynamic table without emitting header
   fields, each of which has a fixed index over time.  Its entries are
   defined in Appendix A.

   A decoder that encounters an invalid static table index fields associated with
      any particular request.

   o  HEADERS and PUSH_PROMISE frames on a request
   stream or and push stream MUST treat this as a stream error of type
   "HTTP_QPACK_DECOMPRESSION_FAILED".  If this index is received on streams
      reference the table state without modifying it.

   o  The decoder sends feedback to the encoder stream, this MUST be treated as on a connection error of type
   "HTTP_QPACK_ENCODER_STREAM_ERROR".

2.2.  Dynamic Table

   The unidirectional
      stream.  This feedback enables the encoder to manage dynamic table consists of
      state.

2.1.  Encoder

   An encoder compresses a header list of by emitting either an indexed or
   a literal representation for each header fields maintained field in
   first-in, first-out order.  The dynamic table is initially empty.
   Entries are added by instructions on the encoder stream (see
   Section 5.2).

   The maximum size of list.
   References to the dynamic static table can be modified by the encoder,
   subject to a decoder-controlled limit (see Section 4 and
   Section 5.2.4).  The initial maximum size is determined by the
   corresponding setting when HTTP requests or responses are first
   permitted literal representations do not
   require any dynamic state and never risk head-of-line blocking.
   References to be sent.  For clients using 0-RTT data in HTTP/QUIC, the dynamic table size is the remembered value of the setting, even risk head-of-line blocking if the server
   later specifies a larger maximum in its SETTINGS frame.  For HTTP/
   QUIC servers and HTTP/QUIC clients when 0-RTT is
   encoder has not attempted or is
   rejected, received an acknowledgement indicating the initial maximum table size entry is
   available at the value of the setting decoder.

   An encoder MAY insert any entry in the peer's SETTINGS frame.

   Before a new entry dynamic table it chooses; it
   is added not limited to header fields it is compressing.

   QPACK preserves the dynamic table, entries are evicted
   from the end ordering of header fields within each header
   list.  An encoder MUST emit header field representations in the dynamic table until the size of order
   they appear in the dynamic table input header list.

   QPACK is less than or equal designed to (maximum size - new entry size) or until contain the
   table more complex state tracking to the
   encoder, while the decoder is empty.  The relatively simple.

2.1.1.  Reference Tracking

   An encoder MUST NOT evict ensure that a header block which references a dynamic
   table entry
   unless it has first been acknowledged is not received by the decoder.

   If the size of decoder after the new referenced entry is less than or equal to
   has been evicted.  Hence the maximum
   size, that entry is added encoder needs to track information about
   each compressed header block that references the table.  It is an error to attempt to
   add an entry dynamic table until
   that header block is larger than acknowledged by the maximum size; this decoder.

2.1.2.  Blocked Dynamic Table Insertions

   An encoder MUST be
   treated as a connection error of type
   "HTTP_QPACK_ENCODER_STREAM_ERROR".

   A new entry can reference NOT insert an entry in into the dynamic table that will be
   evicted when adding this new (or
   duplicate an existing entry) if doing so would evict an entry into with
   unacknowledged references.  For header blocks that might rely on the dynamic table.
   Implementations are cautioned to avoid deleting
   newly added entry, the referenced name
   if encoder can use a literal representation and
   maybe insert the referenced entry later.

   To ensure that the encoder is evicted not prevented from the dynamic table prior to
   inserting the adding new entry.

   The dynamic table entries,
   the encoder can contain duplicate entries (i.e., avoid referencing entries with that are close to eviction.
   Rather than reference such an entry, the same name encoder can emit a Duplicate
   instruction (see Section 4.3.3), and same value).  Therefore, reference the duplicate instead.

   Determining which entries MUST NOT
   be treated as an error by a decoder.

2.2.1.  Maximum Table Size

   The encoder decides how are too close to update the dynamic table and as such can
   control how much memory is used by the dynamic table.  To limit the
   memory requirements of the decoder, the dynamic table size eviction to reference is
   strictly bounded.

   The decoder determines the maximum size that the
   an encoder preference.  One heuristic is permitted to use for target a fixed amount of
   available space in the dynamic table.  In HTTP/QUIC, this value is determined table: either unused space or space
   that can be reclaimed by evicting unreferenced entries.  To achieve
   this, the SETTINGS_HEADER_TABLE_SIZE setting (see Section 4).

   An encoder can choose to use less capacity than this maximum size
   (see Section 5.2.4), but the chosen size MUST stay lower than or
   equal to the maximum set by the decoder.  Whenever maintain a draining index, which is the maximum size
   for
   smallest absolute index in the dynamic table is reduced, that it will emit a
   reference for.  As new entries are evicted from inserted, the end of encoder increases
   the dynamic table until draining index to maintain the size section of the dynamic table is less than or
   equal to that it will
   not reference.  If the maximum size.

   This mechanism can be used encoder does not create new references to completely clear
   entries from with an absolute index lower than the
   dynamic table by setting a maximum size draining index, the
   number of 0, which can subsequently
   be restored.

2.2.2.  Calculating unacknowledged references to those entries will eventually
   become zero, allowing them to be evicted.

      +----------+---------------------------------+--------+
      | Draining |          Referenceable          | Unused |
      | Entries  |             Entries             | Space  |
      +----------+---------------------------------+--------+
      ^          ^                                 ^
      |          |                                 |
    Dropping    Draining Index               Base Index /
     Point                                   Insertion Point

                 Figure 1: Draining Dynamic Table Size

   The size of Entries

2.1.3.  Avoiding Head-of-Line Blocking

   Because QUIC does not guarantee order between data on different
   streams, a header block might reference an entry in the dynamic table is the sum of
   that has not yet been received.

   Each header block contains a Largest Reference (Section 4.5.1) which
   identifies the size of its entries.

   The size of an entry is table state necessary for decoding.  If the sum of its name's length in octets (as
   defined in Section 5.1.2), its value's length greatest
   absolute index in octets, and 32.

   The size of an entry is calculated using the length of its name and
   value without any Huffman encoding applied.

   "MaxEntries" dynamic table is less than the maximum number value of entries that the dynamic table
   can have.  The smallest entry has empty name and value strings and
   has
   Largest Reference, the size of 32.  The MaxEntries stream is calculated as

      MaxEntries = floor( MaxTableSize / 32 )

   MaxTableSize considered "blocked."  While
   blocked, header field data SHOULD remain in the blocked stream's flow
   control window.  When the Largest Reference is zero, the maximum size of frame
   contains no references to the dynamic table as specified by and can always be
   processed immediately.  A stream becomes unblocked when the decoder (see Section 2.2.1).

2.2.3.  Absolute Indexing

   Each entry possesses both an greatest
   absolute index which is fixed for in the
   lifetime of that entry and a relative index which changes over time
   based on dynamic table becomes greater than or equal to
   the context of Largest Reference for all header blocks the reference.  The first entry inserted decoder has
   an absolute index of "1"; indices increase sequentially with each
   insertion.

2.2.4.  Relative Indexing

   The relative index begins at zero and increases in the opposite
   direction started
   reading from the absolute index.  Determining which entry has a
   relative index of "0" depends on the context of the reference.

   On stream.  If the encoder stream, decoder encounters a relative index of "0" always refers header block
   where the actual largest reference is not equal to the
   most recently inserted value Largest
   Reference declared in the dynamic table.  Note that prefix, it MAY treat this
   means the entry referenced by as a given relative index will change
   while interpreting instructions stream error
   of type HTTP_QPACK_DECOMPRESSION_FAILED.

   The SETTINGS_QPACK_BLOCKED_STREAMS setting (see Section 5) specifies
   an upper bound on the encoder stream.

       +---+---------------+-----------+
       | n |      ...      |   d + 1   |  Absolute Index
       + - +---------------+ - - - - - +
       | 0 |      ...      | n - d - 1 |  Relative Index
       +---+---------------+-----------+
         ^                       |
         |                       V
   Insertion Point         Dropping Point

   n = count of entries inserted
   d = count number of entries dropped

              Example Dynamic Table Indexing - Control Stream

   Because frames from request streams which can be delivered out of order
   with instructions on the blocked.  An
   encoder stream, relative indices are
   relative to the Base Index at MUST limit the beginning number of streams which could become blocked
   to the header block (see
   Section 5.4.1).  The Base Index is an absolute index.  When
   interpreting the rest value of SETTINGS_QPACK_BLOCKED_STREAMS at all times.  Note
   that the frame, the entry identified by Base
   Index has a relative index of zero.  The relative indices of entries
   do decoder might not change while interpreting headers actually become blocked on every stream
   which risks becoming blocked.  If the decoder encounters more blocked
   streams than it promised to support, it MUST treat this as a request or push stream.

                Base Index
                    |
                    V
       +---+-----+-----+-----+-------+
       | n | n-1 | n-2 | ... |  d+1  |  Absolute Index
       +---+-----+  -  +-----+   -   +
                 |  0  | ... | n-d-3 |  Relative Index
                 +-----+-----+-------+

   n = count stream
   error of entries inserted
   d = count type HTTP_QPACK_DECOMPRESSION_FAILED.

   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 dropped

     Example Dynamic Table Indexing - Relative Index on Request Stream

2.2.5.  Post-Base Indexing

   A header block on that are still in transit, but if there is loss or
   reordering the request stream can reference entries added
   after become blocked at the entry identified decoder.  An encoder
   avoids the risk of blocking by only referencing dynamic table entries
   which have been acknowledged, but this could mean using literals.
   Since literals make the Base Index.  This allows an encoder
   to process a header block in a single pass and include references to
   entries added while processing larger, this (or other) header blocks.  Newly
   added entries are referenced using Post-Base instructions.  Indices
   for Post-Base instructions increase can result in the same direction as absolute
   indices, but the zero value is one higher than the Base Index.

                Base Index
                    |
                    V
       +---+-----+-----+-----+-----+
       | n | n-1 | n-2 | ... | d+1 |  Absolute Index
       +---+-----+-----+-----+-----+
       | 1 |  0  |                    Post-Base Index
       +---+-----+

   n = count of entries inserted
   d = count of entries dropped

    Example Dynamic Table Indexing - Post-Base Index on Request Stream

   If the decoder encounters a reference
   encoder becoming blocked on a request congestion or push stream flow control limits.

2.1.4.  Largest Known Received

   In order to
   a identify which dynamic table entry which has already been dropped or which has an
   absolute index greater than the declared Largest Reference (see
   Section 5.4.1), it MUST treat this as entries can be safely used
   without a stream error becoming blocked, the encoder tracks the absolute
   index of type
   "HTTP_QPACK_DECOMPRESSION_FAILED".

   If the decoder encounters a reference on decoder's Largest Known Received entry.

   When blocking references are permitted, the encoder stream to a
   dynamic table entry which has already been dropped, it MUST treat
   this as a connection error of type "HTTP_QPACK_ENCODER_STREAM_ERROR".

2.3.  Avoiding Head-of-Line Blocking in HTTP/QUIC

   Because QUIC does not guarantee order between data on different
   streams, a uses header block might reference an entry in
   acknowledgement to identify the Largest Known Received index, as
   described in Section 4.4.2.

   To acknowledge dynamic table
   that has entries which are not yet been received.

   Each referenced by
   header block contains a Largest Reference which identifies the
   table state necessary blocks, for decoding.  If example because the greatest absolute index encoder or the decoder have
   chosen not to risk blocked streams, the decoder sends a Table State
   Synchronize instruction (see Section 4.4.1).

2.2.  Decoder

   As in HPACK, the decoder processes header blocks and emits the
   corresponding header lists.  It also processes dynamic table is less than the value of the Largest Reference,
   modifications from instructions on the stream is considered "blocked."  While blocked, encoder stream.

   The decoder MUST emit header field data
   should remain fields in the blocked stream's flow control window.  When the
   Largest Reference is zero, the frame contains no references to the
   dynamic table and can always be processed immediately.  A stream
   becomes unblocked when the greatest absolute index order their
   representations appear in the dynamic
   table becomes greater than or equal to the Largest Reference for all input header blocks the block.

2.2.1.  State Synchronization

   The decoder has started reading from stream (Section 4.4) signals key events at the stream.  If a decoder encounters a header block where
   that permit the actual largest reference
   is not equal encoder to track the Largest Reference declared in the prefix, it MAY
   treat this as a stream error of type HTTP_QPACK_DECOMPRESSION_FAILED.

   A decoder can permit the possibility decoder's state.  These events
   are:

   o  Complete processing of blocked streams by setting
   SETTINGS_QPACK_BLOCKED_STREAMS to a non-zero value (see Section 4).
   This setting specifies an upper bound on the number header block

   o  Abandonment of streams which
   can be blocked.

   An encoder can decide whether to risk having a stream become blocked.
   If permitted by the value which might have remaining header blocks

   o  Receipt of SETTINGS_QPACK_BLOCKED_STREAMS,
   compression efficiency can be improved by referencing new dynamic table entries

   Knowledge that are still in transit, but if there is loss or reordering
   the stream can become blocked at the decoder.  An encoder avoids a header block with references to the
   risk of blocking by only referencing dynamic table entries which have
   has been acknowledged, but this means using literals.  Since literals
   make the header block larger, this can result in the encoder becoming
   blocked on congestion or flow control limits.

   An encoder MUST limit the number of streams which could become
   blocked to the value of SETTINGS_QPACK_BLOCKED_STREAMS at all times.
   Note that the decoder might not actually become blocked on every
   stream which risks becoming blocked.  If the decoder encounters more
   blocked streams than it promised to support, it MUST treat this as a
   stream error of type HTTP_QPACK_DECOMPRESSION_FAILED.

2.3.1.  State Synchronization

   The decoder stream (Section 5.3) signals key events at the decoder
   that permit the encoder to track the decoder's state.  These events
   are:

   o  Complete processing of a header block

   o  Abandonment of a stream which might have remaining header blocks

   o  Receipt of new dynamic table entries

   Regardless of whether a header block contained blocking references,
   the knowledge that it has been processed permits processed permits the encoder to evict entries to which no
   unacknowledged references remain; see remain, regardless of whether those
   references were potentially blocking (see Section 7.3.1. 2.1.2).  When a
   stream is reset or abandoned, the indication that these header blocks
   will never be processed serves a similar function; see Section 5.3.3.

   For the encoder to identify which dynamic table entries can be safely
   used without a stream becoming blocked, the encoder tracks the
   absolute index of the decoder's Largest Known Received entry.

   When blocking references are permitted, the encoder uses
   acknowledgement of header blocks 4.4.3.

   The decoder chooses when to identify the Largest Known
   Received index, as described in emit Table State Synchronize instructions
   (see Section 5.3.2.

   To acknowledge 4.4.1).  Emitting an instruction after adding each new
   dynamic table entries which are not referenced by
   header blocks, for example because the encoder or entry will provide the decoder have
   chosen not most timely feedback to risk blocked streams, the
   encoder, but could be redundant with other decoder sends feedback.  By
   delaying a Table State Synchronize instruction instruction, the decoder might be
   able to coalesce multiple Table State Synchronize instructions, or
   replace them entirely with Header Acknowledgements (see
   Section 5.3.1).

3.  Conventions and Definitions

   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
   "OPTIONAL" in this document are 4.4.2).  However, delaying too long may lead to be interpreted as described in BCP
   14 [RFC2119] [RFC8174] when, and only when, they appear in all
   capitals, as shown here.

   Definitions of terms that are used in this document:

   Header field:  A name-value pair sent as part of an HTTP message.

   Header list:  The ordered collection of header fields associated with compression
   inefficiencies if the encoder waits for an HTTP message.  A header list entry to be acknowledged
   before using it.

2.2.2.  Blocked Decoding

   To track blocked streams, the necessary Largest Reference value for
   each stream can contain multiple header fields
      with be used.  Whenever the same name.  It decoder processes a table
   update, it can also contain duplicate header fields. begin decoding any blocked streams that now have their
   dependencies satisfied.

3.  Header block: Tables

   Unlike in HPACK, entries in the QPACK static and dynamic tables are
   addressed separately.  The compressed representation following sections describe how entries in
   each table are addressed.

3.1.  Static Table

   The static table consists of a header list.

   Encoder:  An implementation which transforms a header predefined static list into a of header block.

   Decoder:  An implementation
   fields, each of which transforms a header block into has a
      header list. fixed index over time.  Its entries are
   defined in Appendix A.

   Note the QPACK static table is a name, not an acronym.

3.1.  Notational Conventions

   Diagrams use the format described in Section 3.1 of [RFC2360], with indexed from 0, whereas the following additional conventions:

   x (A)  Indicates that x HPACK
   static table is A bits long

   x (A+)  Indicates that x uses indexed from 1.

   When the prefixed integer encoding defined
      in Section 5.1 of [RFC7541], beginning with decoder encounters an A-bit prefix.

   x ...  Indicates that x is variable-length and extends to the end invalid static table index on a
   request stream or push stream it MUST treat this as a stream error of
   type "HTTP_QPACK_DECOMPRESSION_FAILED".  If this index is received on
   the region.

4.  Configuration

   QPACK defines two settings which are included in the HTTP/QUIC
   SETTINGS frame.

   SETTINGS_HEADER_TABLE_SIZE (0x1):  An integer with encoder stream, this MUST be treated as a maximum value connection error of
      2^30 - 1.
   type "HTTP_QPACK_ENCODER_STREAM_ERROR".

3.2.  Dynamic Table

   The default value is 4,096 bytes.  See Section 2.2 for
      usage.

   SETTINGS_QPACK_BLOCKED_STREAMS (0x7):  An integer with dynamic table consists of a maximum
      value list of 2^16 - 1. header fields maintained in
   first-in, first-out order.  The default value dynamic table is 100.  See Section 2.3.

5.  Wire Format

   QPACK initially empty.
   Entries are added by instructions occur in three locations, each of which uses a
   separate instruction space:

   o  The on the encoder stream is a unidirectional stream (see
   Section 4.3).

   The maximum size of type "0x48"
      (ASCII 'H') which carries table updates from encoder to decoder.
      Instructions on this stream modify the dynamic table state without
      generating output can be modified by the encoder,
   subject to any particular request.

   o  The decoder stream is a unidirectional stream of type "0x68"
      (ASCII 'h') which carries acknowledgements of table modifications decoder-controlled limit (see Section 5 and header processing from decoder
   Section 4.3.4).  The initial maximum size is determined by the
   corresponding setting when HTTP requests or responses are first
   permitted to encoder.

   o  Finally, be sent.  For clients using 0-RTT data in HTTP/3, the contents
   table size is the remembered value of HEADERS and PUSH_PROMISE frames on
      request streams the setting, even if the server
   later specifies a larger maximum in its SETTINGS frame.  For HTTP/3
   servers and push streams reference HTTP/3 clients when 0-RTT is not attempted or is
   rejected, the QPACK initial maximum table state.

   There MUST be exactly one size is the value of each unidirectional stream type the setting
   in each
   direction.  Receipt of the peer's SETTINGS frame.

   Before a second instance new entry is added to the dynamic table, entries are evicted
   from the end of either stream type the dynamic table until the size of the dynamic table
   is less than or equal to (maximum size - new entry size) or until the
   table is empty.  The encoder MUST
   be treated as NOT evict a connection error of HTTP_WRONG_STREAM_COUNT.  Closure dynamic table entry
   unless it has first been acknowledged by the decoder.

   If the size of either unidirectional stream the new entry is less than or equal to the maximum
   size, that entry is added to the table.  It is an error to attempt to
   add an entry that is larger than the maximum size; this MUST be
   treated as a connection error of type HTTP_CLOSED_CRITICAL_STREAM.

   This section describes
   "HTTP_QPACK_ENCODER_STREAM_ERROR".

   A new entry can reference an entry in the instructions which are possible on each
   stream type.

   All dynamic table updates occur on the encoder stream.  Request streams and
   push streams only carry header blocks that do not modify the state of will be
   evicted when adding this new entry into the dynamic table.

5.1.  Primitives

5.1.1.  Prefixed Integers

   The prefixed integer from Section 5.1 of [RFC7541]
   Implementations are cautioned to avoid deleting the referenced name
   if the referenced entry is used heavily
   throughout this document.  The format evicted from [RFC7541] is used
   unmodified.  QPACK implementations MUST be able to decode integers up the dynamic table prior to 62 bits long.

5.1.2.  String Literals
   inserting the new entry.

   The string literal defined by Section 5.2 of [RFC7541] is also used
   throughout.  This string format includes optional Huffman encoding.

   HPACK defines string literals to begin on a byte boundary.  They
   begin dynamic table can contain duplicate entries (i.e., entries with a single flag (indicating whether
   the string is Huffman-
   coded), followed same name and same value).  Therefore, duplicate entries MUST NOT
   be treated as an error by the Length encoded as a 7-bit prefix integer, and
   finally Length octets of data.  When Huffman encoding is enabled, decoder.

3.2.1.  Maximum Table Size

   The encoder decides how to update the
   Huffman dynamic table from Appendix B of [RFC7541] and as such can
   control how much memory is used without
   modification.

   This document expands by the definition dynamic table.  To limit the
   memory requirements of string literals and permits
   them to begin other than on a byte boundary.  An "N-bit prefix string
   literal" begins with the same Huffman flag, followed by decoder, the length
   encoded as an (N-1)-bit prefix integer. dynamic table size is
   strictly bounded.

   The remainder of decoder determines the string
   literal is unmodified.

   A string literal without a prefix length noted maximum size that the encoder is an 8-bit prefix
   string literal and follows the definitions in [RFC7541] without
   modification.

5.2.  QPACK Encoder Stream

   Table updates can add a table entry, possibly using existing entries
   to avoid transmitting redundant information.  The name can be
   transmitted as a reference permitted
   to an existing entry in the static or the
   dynamic table or as a string literal.  For entries which already
   exist in use for the dynamic table, the full entry can also be used table.  In HTTP/3, this value is determined by
   reference, creating a duplicate entry.

   The contents of
   the SETTINGS_HEADER_TABLE_SIZE setting (see Section 5).

   An encoder stream are an unframed sequence of can choose to use less capacity than this maximum size
   (see Section 4.3.4), but the
   following instructions.

5.2.1.  Insert With Name Reference

   An addition chosen size MUST stay lower than or
   equal to the header table where maximum set by the header field name matches decoder.  Whenever the header field name of an entry stored in maximum size
   for the static dynamic table or is reduced, entries are evicted from the end of
   the dynamic table starts with until the '1' one-bit pattern.  The "S" bit
   indicates whether size of the reference dynamic table is less than or
   equal to the static (S=1) or dynamic
   (S=0) table.  The 6-bit prefix integer (see Section 5.1 of [RFC7541])
   that follows is maximum size.

   This mechanism can be used to locate completely clear entries from the
   dynamic table entry for the header name.
   When S=1, the number represents by setting a maximum size of 0, which can subsequently
   be restored.

3.2.2.  Calculating Table Size

   The size of the static dynamic table index; when S=0, the
   number is the relative index sum of the size of its entries.

   The size of an entry in is the dynamic table. sum of its name's length in bytes (as
   defined in Section 4.1.2), its value's length in bytes, and 32.

   The header name reference size of an entry is followed by calculated using the header field length of its name and
   value
   represented as a string literal (see Section 5.2 without any Huffman encoding applied.

   "MaxEntries" is the maximum number of [RFC7541]).

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 1 | S |    Name Index (6+)    |
      +---+---+-----------------------+
      | H |     Value Length (7+)     |
      +---+---------------------------+
      | Value String (Length octets)  |
      +-------------------------------+

                    Insert Header Field -- Indexed Name

5.2.2.  Insert Without Name Reference

   An addition to entries that the header dynamic table where both the header field
   can have.  The smallest entry has empty name and
   the header field value are represented as string literals (see
   Section 5.1) starts with strings and
   has the '01' two-bit pattern. size of 32.  The name MaxEntries is represented calculated as a 6-bit prefix string literal, while the
   value

      MaxEntries = floor( MaxTableSize / 32 )

   MaxTableSize is represented as an 8-bit prefix string literal.

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 0 | 1 | H | Name Length (5+)  |
      +---+---+---+-------------------+
      |  Name String (Length octets)  |
      +---+---------------------------+
      | H |     Value Length (7+)     |
      +---+---------------------------+
      | Value String (Length octets)  |
      +-------------------------------+

                      Insert Header Field -- New Name

5.2.3.  Duplicate

   Duplication the maximum size of an existing entry in the dynamic table starts with as specified by
   the
   '000' three-bit pattern.  The relative decoder (see Section 3.2.1).

3.2.3.  Absolute Indexing

   Each entry possesses both an absolute index of which is fixed for the existing
   lifetime of that entry is
   represented as an integer with and a 5-bit prefix.

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 0 | 0 | 0 |    Index (5+)     |
      +---+---+---+-------------------+

                            Figure 1: Duplicate

   The existing entry is re-inserted into the dynamic table without
   resending either the name or the value.  This is useful to mitigate
   the eviction of older entries relative index which are frequently referenced, both
   to avoid the need to resend changes based on
   the header and to avoid context of the reference.  The first entry inserted has an
   absolute index of "1"; indices increase sequentially with each
   insertion.

3.2.4.  Relative Indexing

   The relative index begins at zero and increases in the
   table blocking opposite
   direction from the ability to insert new headers.

5.2.4.  Dynamic Table Size Update

   An encoder informs absolute index.  Determining which entry has a
   relative index of "0" depends on the decoder context of the reference.

   On the encoder stream, a change relative index of "0" always refers to the size of
   most recently inserted value in the dynamic
   table using an instruction which begins with table.  Note that this
   means the '001' three-bit
   pattern.  The new maximum table size is represented as an integer
   with entry referenced by a 5-bit prefix (see Section 5.1 of [RFC7541]).

     0 given relative index will change
   while interpreting instructions on the encoder stream.

       +---+---------------+-----------+
       | n |      ...      |   d + 1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+   | 0  Absolute Index
       + - +---------------+ - - - - - +
       | 0 |      ...      | n - d - 1 |   Max size (5+)  Relative Index
       +---+---------------+-----------+
         ^                       |
   +---+---+---+-------------------+

                Figure 2: Maximum Dynamic Table Size Change

   The new maximum size MUST be lower than or equal to the limit
   determined by the protocol using QPACK.  A value that exceeds this
   limit MUST be treated as a connection error
         |                       V
   Insertion Point         Dropping Point

   n = count of type
   "HTTP_QPACK_ENCODER_STREAM_ERROR".  In HTTP/QUIC, this limit is the
   value entries inserted
   d = count of the SETTINGS_HEADER_TABLE_SIZE parameter (see Section 4)
   received entries dropped

              Example Dynamic Table Indexing - Control Stream

   Because frames from the decoder.

   Reducing the maximum size of the dynamic table request streams can cause entries to be evicted (see Section 4.3 of [RFC7541]).  This MUST NOT cause the
   eviction delivered out of entries order
   with outstanding references (see Section 7.3).
   Changing the size of the dynamic table is not acknowledged as this
   instruction does not insert an entry.

5.3.  QPACK Decoder Stream

   The decoder stream carries information used to ensure consistency of
   the dynamic table.  Information is sent from instructions on the QPACK decoder encoder stream, relative indices are
   relative to the
   QPACK encoder; that is, the server informs the client about the
   processing of the client's header blocks and table updates, and the
   client informs the server about Base Index at the processing beginning of the server's header
   blocks and table updates. block (see
   Section 4.5.1).  The contents of the decoder stream are Base Index is an unframed sequence absolute index.  When
   interpreting the rest of the
   following instructions.

5.3.1.  Table State Synchronize

   The Table State Synchronize instruction begins with frame, the '00' two-bit
   pattern. entry identified by Base
   Index has a relative index of zero.  The instruction specifies the total number relative indices of dynamic table
   inserts and duplications since the last Table State Synchronize or
   Header Acknowledgement that increased the Largest Known Received
   dynamic table entry.  This is encoded as a 6-bit prefix integer.  The
   encoder uses this value to determine which table entries might cause
   do not change while interpreting headers on a stream to become blocked, as described in Section 2.3.1.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+ request or push stream.

                Base Index
                    | 0
                    V
       +---+-----+-----+-----+-------+
       | n | n-1 | n-2 | ... |  d+1  |  Absolute Index
       +---+-----+  -  +-----+   -   +
                 |  0  |   Insert Count (6+) ... |
   +---+---+-----------------------+

                     Figure 3: Table State Synchronize

   An encoder that receives an Insert Count equal to zero or one that
   increases Largest Known Received beyond what the encoder has sent
   MUST treat this as a connection error n-d-3 |  Relative Index
                 +-----+-----+-------+

   n = count of type
   "HTTP_QPACK_DECODER_STREAM_ERROR".

   A decoder chooses when to emit Table State Synchronize instructions.
   Emitting a entries inserted
   d = count of entries dropped

     Example Dynamic Table State Synchronize after adding each new dynamic
   table entry will provide Indexing - Relative Index on Request Stream

3.2.5.  Post-Base Indexing

   A header block on the most timely feedback to request stream can reference entries added
   after the encoder, but
   could be redundant with other decoder feedback.  By delaying a
   Table State Synchronize, a decoder might be able to coalesce multiple
   Table State Synchronize instructions, or replace them entirely with
   Header Acknowledgements.  However, delaying too long may lead to
   compression inefficiencies if entry identified by the encoder waits for Base Index.  This allows an entry encoder
   to be
   acknowledged before using it.

5.3.2.  Header Acknowledgement

   After processing process a header block whose declared Largest Reference is
   not zero, the decoder emits in a Header Acknowledgement instruction on
   the decoder stream.  The instruction begins with the '1' one-bit
   pattern single pass and includes include references to
   entries added while processing this (or other) header blocks.  Newly
   added entries are referenced using Post-Base instructions.  Indices
   for Post-Base instructions increase in the request stream's stream ID, encoded same direction as a
   7-bit prefix integer.  It is used by absolute
   indices, but the peer's QPACK encoder to know
   when it zero value is safe to evict an entry.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+ one higher than the Base Index.

                Base Index
                    |
                    V
       +---+-----+-----+-----+-----+
       | n | n-1 | n-2 | ... | d+1 |  Absolute Index
       +---+-----+-----+-----+-----+
       | 1 |      Stream ID (7+)  0  |
   +---+---------------------------+

                     Figure 4: Header Acknowledgement

   The same Stream ID can be identified multiple times, as multiple
   header blocks can be sent on a single stream in the case                    Post-Base Index
       +---+-----+

   n = count of
   intermediate responses, trailers, and pushed requests.  Since header
   frames entries inserted
   d = count of entries dropped

    Example Dynamic Table Indexing - Post-Base Index on each stream are received and processed in order, this gives Request Stream

3.2.6.  Invalid References

   If the encoder precise feedback decoder encounters a reference on which header blocks within a request or push stream
   have been fully processed.

   If an encoder receives a Header Acknowledgement instruction referring to
   a stream on dynamic table entry which every header block with a non-zero Largest
   Reference has already been acknowledged, that evicted or which has an
   absolute index greater than the declared Largest Reference (see
   Section 4.5.1), it MUST be treated treat this as a
   connection stream error of type "HTTP_QPACK_DECODER_STREAM_ERROR".

   When blocking references are permitted,
   "HTTP_QPACK_DECOMPRESSION_FAILED".

   If the decoder encounters a reference on the encoder uses
   acknowledgement of header blocks stream to update the Largest Known Received
   index.  If a header block was potentially blocking, the
   acknowledgement implies that the decoder has received all
   dynamic table state necessary entry which has already been dropped, it MUST treat
   this as a connection error of type "HTTP_QPACK_ENCODER_STREAM_ERROR".

4.  Wire Format

4.1.  Primitives

4.1.1.  Prefixed Integers

   The prefixed integer from Section 5.1 of [RFC7541] is used heavily
   throughout this document.  The format from [RFC7541] is used
   unmodified.  QPACK implementations MUST be able to process the header block.  If the Largest
   Reference decode integers up
   to 62 bits long.

4.1.2.  String Literals

   The string literal defined by Section 5.2 of an acknowledged header block was greater than the
   encoder's current Largest Known Received index, the block's Largest
   Reference becomes the new Largest Known Received.

5.3.3.  Stream Cancellation

   A stream that [RFC7541] is reset might have multiple outstanding header blocks also used
   throughout.  This string format includes optional Huffman encoding.

   HPACK defines string literals to begin on a byte boundary.  They
   begin with dynamic table references.  A decoder that receives a stream
   reset before single flag (indicating whether the end of a stream generates a Stream Cancellation
   instruction on string is Huffman-
   coded), followed by the decoder stream.  Similarly, Length encoded as a decoder that
   abandons reading 7-bit prefix integer, and
   finally Length bytes of a stream needs to signal this using data.  When Huffman encoding is enabled, the Stream
   Cancellation instruction.
   Huffman table from Appendix B of [RFC7541] is used without
   modification.

   This signals to the encoder that all
   references to document expands the dynamic table definition of string literals and permits
   them to begin other than on that stream are no longer
   outstanding.  A decoder with a maximum dynamic table size equal to
   zero MAY omit sending Stream Cancellations, because the encoder
   cannot have any dynamic table references. byte boundary.  An encoder cannot infer from this instruction that any updates to the
   dynamic table have been received.

   The instruction "N-bit prefix string
   literal" begins with the '01' two-bit pattern.  The
   instruction includes same Huffman flag, followed by the stream ID length
   encoded as an (N-1)-bit prefix integer.  The remainder of the affected string
   literal is unmodified.

   A string literal without a prefix length noted is an 8-bit prefix
   string literal and follows the definitions in [RFC7541] without
   modification.

4.2.  Stream Types

   QPACK instructions occur in three locations, each of which uses a
   separate instruction space:

   o  The encoder stream - is a request
   or push unidirectional stream - encoded as of type "0x48"
      (ASCII 'H') which carries table updates from encoder to decoder.

   o  The decoder stream is a 6-bit prefix integer.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 |     Stream ID (6+)    |
   +---+---+-----------------------+

                       Figure 5: Stream Cancellation

5.4.  Request unidirectional stream of type "0x68"
      (ASCII 'h') which carries acknowledgements of table modifications
      and Push Streams header processing from decoder to encoder.

   o  Finally, the contents of HEADERS and PUSH_PROMISE frames on
      request streams and push streams reference the dynamic QPACK table state.

   There MUST be exactly one of each unidirectional stream type in each
   direction.  Receipt of a particular state without modifying it.  Frames
   on these streams emit the headers for an HTTP request or response.

5.4.1.  Header Data Prefix

   Header data is prefixed with two integers, "Largest Reference" and
   "Base Index".

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   |     Largest Reference (8+)    |
   +---+---------------------------+
   | S |   Delta Base Index (7+)   |
   +---+---------------------------+
   |      Compressed Headers     ...
   +-------------------------------+

                          Figure 6: Frame Payload

   "Largest Reference" identifies second instance of either stream type MUST
   be treated as a connection error of HTTP_WRONG_STREAM_COUNT.  Closure
   of either unidirectional stream MUST be treated as a connection error
   of type HTTP_CLOSED_CRITICAL_STREAM.

   This section describes the instructions which are possible on each
   stream type.

4.3.  Encoder Stream

   Table updates can add a table entry, possibly using existing entries
   to avoid transmitting redundant information.  The name can be
   transmitted as a reference to an existing entry in the static or the largest absolute
   dynamic index
   referenced table or as a string literal.  For entries which already
   exist in the block.  Blocking decoders use dynamic table, the Largest full entry can also be used by
   reference, creating a duplicate entry.

   The contents of the encoder stream are an unframed sequence of the
   following instructions.

4.3.1.  Insert With Name Reference

   An addition to determine when it is safe to process the rest header table where the header field name matches
   the header field name of an entry stored in the block.  If
   Largest Reference is greater than zero, static table or the encoder transforms it as
   follows before encoding:

      LargestReference = LargestReference mod 2*MaxEntries + 1
   dynamic table starts with the '1' one-bit pattern.  The decoder reconstructs "S" bit
   indicates whether the Largest Reference using reference is to the following
   algorithm:

      if LargestReference > 0:
         LargestReference -= 1
         CurrentWrapped = TableLargestAbsoluteIndex mod 2*MaxEntries

         if CurrentWrapped >= LargestReference + MaxEntries:
            # Largest Reference wrapped around 1 extra time
            LargestReference += 2*MaxEntries
         else if CurrentWrapped + MaxEntries < LargestReference
            # Decoder wrapped around 1 extra time
            CurrentWrapped += 2*MaxEntries

         LargestReference +=
            (TableLargestAbsoluteIndex - CurrentWrapped)

   TableLargestAbsoluteIndex is the Absolute Index of the most recently
   inserted item in the decoder's static (S=1) or dynamic
   (S=0) table.  This encoding limits
   the length of the  The 6-bit prefix on long-lived connections.

   "Base Index" is used to resolve references in the dynamic table as
   described in integer (see Section 2.2.4.

   To save space, Base Index is encoded relative to Largest Reference
   using a one-bit sign and the "Delta Base Index" value.  A sign bit 5.1 of
   0 indicates that the Base Index has an absolute index [RFC7541])
   that follows is greater
   than or equal to the Largest Reference; the value of Delta Base Index
   is added used to locate the Largest Reference to determine table entry for the absolute value of header name.
   When S=1, the Base Index.  A sign bit of 1 indicates that number represents the Base Index is
   less than static table index; when S=0, the Largest Reference.  That is:

      if sign == 0:
         baseIndex = largestReference + deltaBaseIndex
      else:
         baseIndex = largestReference - deltaBaseIndex

   A single-pass encoder
   number is expected to determine the absolute value relative index of
   Base Index before encoding a header block.  If the encoder inserted
   entries entry in the dynamic table while encoding the table.

   The header block, Largest
   Reference will be greater than Base Index, so the encoded difference
   is negative and the sign bit name reference is set to 1.  If followed by the header block did
   not reference the most recent entry in the table and did not insert
   any new entries, Base Index will be greater than the Largest
   Reference, so the delta will be positive and the sign bit is set to
   0.

   An encoder that produces table updates before encoding a header block
   might set Largest Reference and Base Index to the same value.  When
   Largest Reference and Base Index are equal, the Delta Base Index is
   encoded with a zero sign bit.  A sign bit set to 1 when the Delta
   Base Index is 0 MUST be treated as a decoder error.

   A header block that does not reference the dynamic table can use any
   value for Base Index; setting both Largest Reference and Base Index
   to zero is the most efficient encoding.

5.4.2.  Instructions

5.4.2.1.  Indexed Header Field

   An indexed header field representation identifies an entry in either
   the static table or the dynamic table and causes that header field to
   be added to the decoded header list, value
   represented as described in a string literal (see Section 3.2 5.2 of
   [RFC7541]. [RFC7541]).

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 1 | S |    Name Index (6+)    |
      +---+---+-----------------------+

                           Indexed
      | H |     Value Length (7+)     |
      +---+---------------------------+
      |  Value String (Length bytes)  |
      +-------------------------------+

                    Insert Header Field

   If the entry is in the static table, or in the dynamic table with an
   absolute index less than or equal -- Indexed Name

4.3.2.  Insert Without Name Reference

   An addition to Base Index, this representation
   starts with the '1' 1-bit pattern, followed by the "S" bit indicating
   whether the reference is into the static (S=1) or dynamic (S=0)
   table.  Finally, header table where both the relative index of header field name and
   the matching header field is value are represented as an integer with a 6-bit prefix string literals (see
   Section 5.1 of
   [RFC7541]).

5.4.2.2.  Indexed 4.1) starts with the '01' two-bit pattern.

   The name is represented as a 6-bit prefix string literal, while the
   value is represented as an 8-bit prefix string literal.

        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)  |
      +-------------------------------+

                      Insert Header Field With Post-Base Index

   If the -- New Name

4.3.3.  Duplicate

   Duplication of an existing entry is in the dynamic table with an absolute index greater
   than Base Index, the representation starts with the '0001' 4-bit
   pattern, followed by the post-base
   '000' three-bit pattern.  The relative index (see Section 2.2.5) of the
   matching header field, existing entry is
   represented as an integer with a 4-bit prefix
   (see Section 5.1 of [RFC7541]). 5-bit prefix.

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 0 | 0 | 0 | 1 |    Index (4+) (5+)     |
   +---+---+---+---+---------------+

                 Indexed Header Field with Post-Base Index

5.4.2.3.  Literal Header Field With Name Reference

   A literal header field with a name reference represents a header
   where the header field name matches the header field name of an
      +---+---+---+-------------------+

                            Figure 2: Duplicate

   The existing entry
   stored in is re-inserted into the static dynamic table or without
   resending either the dynamic table.

   If name or the entry value.  This is in useful to mitigate
   the static table, or in eviction of older entries which are frequently referenced, both
   to avoid the dynamic table with an
   absolute index less than or equal need to Base Index, this representation
   starts with resend the '01' two-bit pattern.  If header and to avoid the entry is in the dynamic
   table with an absolute index greater than Base Index, the
   representation starts with blocking the '0000' four-bit pattern.

   The following bit, 'N', indicates whether an intermediary is
   permitted ability to add this header insert new headers.

4.3.4.  Dynamic Table Size Update

   An encoder informs the decoder of a change to the size of the dynamic header
   table on
   subsequent hops.  When using an instruction which begins with the 'N' bit '001' three-bit
   pattern.  The new maximum table size is set, the encoded header MUST
   always be encoded with a literal representation.  In particular, when
   a peer sends a header field that it received represented as a literal
   header field an integer
   with the 'N' bit set, it MUST use a literal
   representation to forward this header field.  This bit is intended
   for protecting header field values that are not to be put at risk by
   compressing them 5-bit prefix (see Section 7.1 5.1 of [RFC7541] for more details). [RFC7541]).

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 | N | S |Name Index (4+)|
      +---+---+---+---+---------------+
      | H |     Value Length (7+) 0 |
      +---+---------------------------+ 1 | Value String (Length octets)   Max size (5+)   |
      +-------------------------------+

                 Literal Header Field With Name Reference

   For entries in the static table or in the dynamic table with an
   absolute index less
   +---+---+---+-------------------+

                Figure 3: Maximum Dynamic Table Size Change

   The new maximum size MUST be lower than or equal to Base Index, the header field
   name is represented using limit
   determined by the relative index of protocol using QPACK.  A value that entry, which is
   represented exceeds this
   limit MUST be treated as an integer with a 4-bit prefix connection error of type
   "HTTP_QPACK_ENCODER_STREAM_ERROR".  In HTTP/3, this limit is the
   value of the SETTINGS_HEADER_TABLE_SIZE parameter (see Section 5.1 of
   [RFC7541]).  The "S" bit indicates whether 5)
   received from the reference is to decoder.

   Reducing the
   static (S=1) or dynamic (S=0) table.

5.4.2.4.  Literal Header Field With Post-Base Name Reference

   For entries in maximum size of the dynamic table can cause entries to
   be evicted (see Section 4.3 of [RFC7541]).  This MUST NOT cause the
   eviction of entries with outstanding references (see Section 2.1.1).
   Changing the size of the dynamic table is not acknowledged as this
   instruction does not insert an absolute index greater than
   Base Index, entry.

4.4.  Decoder Stream

   The decoder stream carries information used to ensure consistency of
   the header field name dynamic table.  Information is represented using sent from the post-base
   index decoder to the
   encoder; that is, the server informs the client about the processing
   of the client's header blocks and table updates, and the client
   informs the server about the processing of the server's header blocks
   and table updates.

   The contents of the decoder stream are an unframed sequence of the
   following instructions.

4.4.1.  Table State Synchronize

   The Table State Synchronize instruction begins with the '00' two-bit
   pattern.  The instruction specifies the total number of dynamic table
   inserts and duplications since the last Table State Synchronize or
   Header Acknowledgement that increased the Largest Known Received
   dynamic table entry (see Section 2.2.5) 2.1.4).  This is encoded as an integer with a
   3-bit prefix. 6-bit
   prefix integer.  The encoder uses this value to determine which table
   entries might cause a stream to become blocked, as described in
   Section 2.2.1.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | 0 | 0 | N |NameIdx(3+)|
      +---+---+---+---+---+-----------+
      | H |     Value Length (7+)     |
      +---+---------------------------+
      | Value String (Length octets)   Insert Count (6+)   |
      +-------------------------------+

            Literal Header Field With Post-Base Name Reference

5.4.2.5.  Literal Header Field Without Name Reference
   +---+---+-----------------------+

                     Figure 4: Table State Synchronize

   An addition to the header table where both the header field name and
   the header field value are represented as string literals (see
   Section 5.1) starts with the '001' three-bit pattern.

   The fourth bit, 'N', indicates whether encoder that receives an intermediary is permitted
   to add this header Insert Count equal to zero or one that
   increases Largest Known Received beyond what the dynamic header table on subsequent hops.

   When the 'N' bit is set, the encoded header encoder has sent
   MUST always be encoded
   with a literal representation.  In particular, when a peer sends a
   header field that it received represented treat this as a literal header field
   with the 'N' bit set, it MUST use connection error of type
   "HTTP_QPACK_DECODER_STREAM_ERROR".

4.4.2.  Header Acknowledgement

   After processing a literal representation to forward
   this header field.  This bit block whose declared Largest Reference is intended for protecting header field
   values that are
   not to be put at risk by compressing them (see
   Section 7.1 of [RFC7541] for more details). zero, the decoder emits a Header Acknowledgement instruction on
   the decoder stream.  The name is represented instruction begins with the '1' one-bit
   pattern and includes the request stream's stream ID, encoded as a 4-bit
   7-bit prefix string literal, while integer.  It is used by the
   value peer's encoder to know when
   it is represented as safe to evict an 8-bit prefix string literal. entry, and possibly update Largest Known
   Received.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | 1 | N | H |NameLen(3+)|
      +---+---+---+---+---+-----------+
      |  Name String (Length octets)  |
      +---+---------------------------+
      | H |     Value Length      Stream ID (7+)       |
   +---+---------------------------+
      | Value String (Length octets)  |
      +-------------------------------+

                Literal

                     Figure 5: Header Field Without Name Reference

6.  Error Handling Acknowledgement

   The following error codes are defined for HTTP/QUIC to indicate
   failures of QPACK which prevent the stream or connection from
   continuing:

   HTTP_QPACK_DECOMPRESSION_FAILED (TBD):  The decoder failed to
      interpret an instruction same Stream ID can be identified multiple times, as multiple
   header blocks can be sent on a request or push single stream in the case of
   intermediate responses, trailers, and is not
      able to continue decoding that pushed requests.  Since header block.
      HTTP_QPACK_ENCODER_STREAM_ERROR (TBD):

      The decoder failed to interpret an instruction
   frames on each stream are received and processed in order, this gives
   the encoder
      stream.  HTTP_QPACK_DECODER_STREAM_ERROR (TBD):

      The encoder failed to interpret an instruction precise feedback on the decoder
      stream.

   Upon encountering an error, which header blocks within a stream
   have been fully processed.

   If an implementation MAY elect encoder receives a Header Acknowledgement instruction referring
   to treat it
   as a connection error even if this document prescribes stream on which every header block with a non-zero Largest
   Reference has already been acknowledged, that it MUST be treated as a stream error.

7.  Encoding Strategies

7.1.  Single Pass Encoding

   An encoder making a single pass over a list
   connection error of headers must choose
   Base Index before knowing Largest Reference. type "HTTP_QPACK_DECODER_STREAM_ERROR".

   When trying to
   reference a blocking references are permitted, the encoder uses
   acknowledgement of header inserted blocks to update the table after encoding has begun, Largest Known Received
   index.  If a header block was potentially blocking, the entry is encoded with different instructions
   acknowledgement implies that tell the decoder has received all dynamic
   table state necessary to use process the header block.  If the Largest
   Reference of an absolute index acknowledged header block was greater than the Base Index.

7.2.  Preventing Eviction Races

   Due to out-of-order arrival, QPACK's eviction algorithm requires
   changes (relative to HPACK) to avoid
   encoder's current Largest Known Received index, the possibility that an indexed
   representation is decoded after block's Largest
   Reference becomes the referenced entry has already been
   evicted.  QPACK employs a two-phase eviction algorithm, in which new Largest Known Received.

4.4.3.  Stream Cancellation

   The instruction begins with the
   encoder will not evict entries '01' two-bit pattern.  The
   instruction includes the stream ID of the affected stream - a request
   or push stream - encoded as a 6-bit prefix integer.

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 1 |     Stream ID (6+)    |
   +---+---+-----------------------+

                       Figure 6: Stream Cancellation

   A stream that is reset might have multiple outstanding (unacknowledged)
   references.

7.3.  Reference Tracking

   An encoder MUST ensure that a header block which references a blocks
   with dynamic table entry is not received by the decoder after the referenced entry
   has already been evicted.  An encoder also respects the limit set by references.  When an endpoint receives a stream
   reset before the decoder end of a stream, it generates a Stream Cancellation
   instruction on the number decoder stream.  Similarly, when an endpoint
   abandons reading of streams that are allowed a stream it needs to become
   blocked.  Even if signal this using the decoder is willing Stream
   Cancellation instruction.  This signals to tolerate blocked streams, the encoder might choose that all
   references to avoid them in certain cases.

   In order the dynamic table on that stream are no longer
   outstanding.  A decoder with a maximum dynamic table size equal to enable this,
   zero MAY omit sending Stream Cancellations, because the encoder will need to track outstanding
   (unacknowledged) header blocks and
   cannot have any dynamic table updates using feedback
   received from the decoder.

7.3.1.  Blocked Dynamic Table Insertions references.

   An encoder MUST NOT insert an entry into cannot infer from this instruction that any updates to the
   dynamic table (or
   duplicate an existing entry) if doing so would evict an entry with
   unacknowledged references.  For header blocks that might rely have been received.

4.5.  Request and Push Streams

   HEADERS and PUSH_PROMISE frames on the
   newly added entry, the encoder can use a literal representation request and
   maybe insert the entry later.

   To ensure that the encoder is not prevented from adding new entries,
   the encoder can avoid referencing entries that will be evicted
   soonest.  Rather than push streams reference such an entry,
   the encoder SHOULD
   emit dynamic table in a Duplicate instruction (see Section 5.2.3), and reference particular state without modifying it.  Frames
   on these streams emit the
   duplicate instead.

   Determining which entries are too close to eviction to reference is headers for an encoder preference.  One heuristic is to target a fixed amount of
   available space in the dynamic table: either unused space HTTP request or space
   that can be reclaimed by evicting unreferenced entries.  To achieve
   this, the encoder can maintain a draining index, which response.

4.5.1.  Header Data Prefix

   Header data is prefixed with two integers, "Largest Reference" and
   "Base Index".

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   |     Largest Reference (8+)    |
   +---+---------------------------+
   | S |   Delta Base Index (7+)   |
   +---+---------------------------+
   |      Compressed Headers     ...
   +-------------------------------+

                          Figure 7: Frame Payload

4.5.1.1.  Largest Reference

   "Largest Reference" identifies the
   smallest largest absolute dynamic index
   referenced in the dynamic table that it will emit a
   reference for.  As new entries are inserted, the encoder increases block.  Blocking decoders use the draining index Largest Reference
   to maintain determine when it is safe to process the section rest of the table that block.  If
   Largest Reference is greater than zero, the encoder transforms it will
   not reference.  Draining entries - entries with an absolute index
   lower than as
   follows before encoding:

      LargestReference = (LargestReference mod (2 * MaxEntries)) + 1

   The decoder reconstructs the draining index Largest Reference using the following
   algorithm:

      if LargestReference > 0:
         LargestReference -= 1
         CurrentWrapped = TotalNumberOfInserts mod (2 * MaxEntries)

         if CurrentWrapped >= LargestReference + MaxEntries:
            # Largest Reference wrapped around 1 extra time
            LargestReference += 2 * MaxEntries
         else if CurrentWrapped + MaxEntries < LargestReference
            # Decoder wrapped around 1 extra time
            CurrentWrapped += 2 * MaxEntries

         LargestReference += TotalNumberOfInserts - will not accumulate new references.
   The CurrentWrapped

   TotalNumberOfInserts is the total number of unacknowledged references to draining entries will
   eventually become zero, making inserts into the entry available for eviction.

      +----------+---------------------------------+--------+
      | Draining |          Referenceable          | Unused |
      | Entries  |             Entries             | Space  |
      +----------+---------------------------------+--------+
      ^          ^                                 ^
      |          |                                 |
    Dropping    Draining Index
   decoder's dynamic table.  This encoding limits the length of the
   prefix on long-lived connections.

4.5.1.2.  Base Index /
     Point                                   Insertion Point

                 Figure 7: Draining Dynamic Table Entries

7.3.2.  Blocked Decoding

   For header blocks encoded in non-blocking mode, the encoder needs to
   forego indexed representations that refer

   "Base Index" is used to table updates which have
   not yet been acknowledged (see Section 5.3).  Since all table updates
   are processed resolve references in sequence on the control stream, an index into the dynamic table as
   described in Section 3.2.4.

   To save space, Base Index is sufficient encoded relative to track which entries have been
   acknowledged.

   To track blocked streams, Largest Reference
   using a one-bit sign and the necessary "Delta Base Index value for each
   stream can be used.  Whenever Index" value.  A sign bit of
   0 indicates that the decoder processes a table update,
   it can begin decoding any blocked streams Base Index has an absolute index that now have their
   dependencies satisfied.

7.4.  Speculative table updates

   Implementations can _speculatively_ send instructions on the encoder
   stream which are not needed for any current HTTP request is greater
   than or response.
   Such headers could be used strategically equal to improve performance.  For
   instance, the encoder might decide Largest Reference; the value of Delta Base Index
   is added to _refresh_ by sending Duplicate
   representations for popular header fields (Section 5.2.3), ensuring
   they have small indices and hence minimal size on the wire.

7.5.  Sample One Pass Encoding Algorithm

   Pseudo-code for single pass encoding, excluding handling Largest Reference to determine the absolute value of
   duplicates, non-blocking mode, and reference tracking.
   the Base Index.  A sign bit of 1 indicates that the Base Index is
   less than the Largest Reference.  That is:

      if sign == 0:
         baseIndex = dynamicTable.baseIndex largestReference = 0
   for header in headers:
     staticIdx = staticTable.getIndex(header)
     if staticIdx:
       encodeIndexReference(streamBuffer, staticIdx)
       continue

     dynamicIdx = dynamicTable.getIndex(header)
     if !dynamicIdx:
       # No matching entry.  Either insert+index or encode literal
       nameIdx = getNameIndex(header)
       if shouldIndex(header) and dynamicTable.canIndex(header):
         encodeLiteralWithIncrementalIndex(controlBuffer, nameIdx,
                                           header)
         dynamicTable.add(header)
         dynamicIdx = dynamicTable.baseIndex

     if !dynamicIdx:
       # Couldn't index it, literal
       if nameIdx <= staticTable.size:
         encodeLiteral(streamBuffer, nameIndex, header) + deltaBaseIndex
      else:
         # encode literal, possibly with nameIdx above
         baseIndex
         encodeDynamicLiteral(streamBuffer, nameIndex, baseIndex,
                              header)
         largestReference = max(largestReference,
                                dynamicTable.toAbsolute(nameIdx))
     else:
       # Dynamic index reference
       assert(dynamicIdx) largestReference = max(largestReference, dynamicIdx)
       # Encode dynamicIdx, possibly with dynamicIdx above baseIndex
       encodeDynamicIndexReference(streamBuffer, dynamicIdx,
                                   baseIndex)

   # encode - deltaBaseIndex

   A single-pass encoder determines the absolute value of Base Index
   before encoding a header block.  If the encoder inserted entries in
   the dynamic table while encoding the header block, Largest Reference
   will be greater than Base Index, so the encoded difference is
   negative and the sign bit is set to 1.  If the header block did not
   reference the most recent entry in the table and did not insert any
   new entries, Base Index will be greater than the Largest Reference,
   so the delta will be positive and the sign bit is set to 0.

   An encoder that produces table updates before encoding a header block
   might set Largest Reference and Base Index to the same value.  When
   Largest Reference and Base Index are equal, the Delta Base Index is
   encoded with a zero sign bit.  A sign bit set to 1 when the Delta
   Base Index is 0 MUST be treated as a decoder error.

   A header block that does not reference the dynamic table can use any
   value for Base Index; setting both Largest Reference and Base Index
   to zero is the most efficient encoding.

4.5.2.  Indexed Header Field

   An indexed header field representation identifies an entry in either
   the static table or the dynamic table and causes that header field to
   be added to the decoded header list, as described in Section 3.2 of
   [RFC7541].

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 1 | S |      Index (6+)       |
   +---+---+-----------------------+

                           Indexed Header Field

   If the entry is in the static table, or in the dynamic table with an
   absolute index less than or equal to Base Index, this representation
   starts with the '1' 1-bit pattern, followed by the "S" bit indicating
   whether the reference is into the static (S=1) or dynamic (S=0)
   table.  Finally, the relative index of the matching header field is
   represented as an integer with a 6-bit prefix (see Section 5.1 of
   [RFC7541]).

4.5.3.  Indexed Header Field With Post-Base Index

   If the entry is in the dynamic table with an absolute index greater
   than Base Index, the representation starts with the '0001' 4-bit
   pattern, followed by the post-base index (see Section 3.2.5) of the
   matching header field, represented as an integer with a 4-bit prefix
   (see Section 5.1 of [RFC7541]).

     0   1   2   3   4   5   6   7
   +---+---+---+---+---+---+---+---+
   | 0 | 0 | 0 | 1 |  Index (4+)   |
   +---+---+---+---+---------------+

                 Indexed Header Field with Post-Base Index

4.5.4.  Literal Header Field With Name Reference

   A literal header field with a name reference represents a header
   where the header field name matches the header field name of an entry
   stored in the static table or the dynamic table.

   If the entry is in the static table, or in the dynamic table with an
   absolute index less than or equal to Base Index, this representation
   starts with the '01' two-bit pattern.  If the entry is in the dynamic
   table with an absolute index greater than Base Index, the
   representation starts with the '0000' four-bit pattern.

   The following bit, 'N', indicates whether an intermediary is
   permitted to add this header to the dynamic header table on
   subsequent hops.  When the 'N' bit is set, the encoded header MUST
   always be encoded with a literal representation.  In particular, when
   a peer sends a header field that it received represented as a literal
   header field with the 'N' bit set, it MUST use a literal
   representation to forward this header field.  This bit is intended
   for protecting header field values that are not to be put at risk by
   compressing them (see Section 7.1 of [RFC7541] for more details).

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 0 | 1 | N | S |Name Index (4+)|
      +---+---+---+---+---------------+
      | H |     Value Length (7+)     |
      +---+---------------------------+
      |  Value String (Length bytes)  |
      +-------------------------------+

                 Literal Header Field With Name Reference

   For entries in the static table or in the dynamic table with an
   absolute index less than or equal to Base Index, the header field
   name is represented using the relative index of that entry, which is
   represented as an integer with a 4-bit prefix (see Section 5.1 of
   [RFC7541]).  The "S" bit indicates whether the reference is to the
   static (S=1) or dynamic (S=0) table.

4.5.5.  Literal Header Field With Post-Base Name Reference

   For entries in the dynamic table with an absolute index greater than
   Base Index, the header field name is represented using the post-base
   index of that entry (see Section 3.2.5) encoded as an integer with a
   3-bit prefix.

        0   1   2   3   4   5   6   7
      +---+---+---+---+---+---+---+---+
      | 0 | 0 | 0 | 0 | N |NameIdx(3+)|
      +---+---+---+---+---+-----------+
      | H |     Value Length (7+)     |
      +---+---------------------------+
      |  Value String (Length bytes)  |
      +-------------------------------+

            Literal Header Field With Post-Base Name Reference

4.5.6.  Literal Header Field Without Name Reference

   An addition to the header table where both the header field name and
   the header field value are represented as string literals (see
   Section 4.1) starts with the '001' three-bit pattern.

   The fourth bit, 'N', indicates whether an intermediary is permitted
   to add this header to the dynamic header table on subsequent hops.
   When the 'N' bit is set, the encoded header MUST always be encoded
   with a literal representation.  In particular, when a peer sends a
   header field that it received represented as a literal header field
   with the 'N' bit set, it MUST use a literal representation to forward
   this header field.  This bit is intended for protecting header field
   values that are not to be put at risk by compressing them (see
   Section 7.1 of [RFC7541] for more details).

   The name is represented as a 4-bit prefix string literal, while the
   value is represented as an 8-bit prefix string literal.

        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)  |
      +-------------------------------+

                Literal Header Field Without Name Reference

5.  Configuration

   QPACK defines two settings which are included in the HTTP/3 SETTINGS
   frame.

   SETTINGS_HEADER_TABLE_SIZE (0x1):  An integer with a maximum value of
      2^30 - 1.  The default value is zero bytes.  See Section 3.2 for
      usage.

   SETTINGS_QPACK_BLOCKED_STREAMS (0x7):  An integer with a maximum
      value of 2^16 - 1.  The default value is zero.  See Section 2.1.3.

6.  Error Handling

   The following error codes are defined for HTTP/3 to indicate failures
   of QPACK which prevent the stream or connection from continuing:

   HTTP_QPACK_DECOMPRESSION_FAILED (TBD):  The decoder failed to
      interpret an instruction on a request or push stream and is not
      able to continue decoding that header block.

   HTTP_QPACK_ENCODER_STREAM_ERROR (TBD):  The decoder failed to
      interpret an instruction on the prefix
   encodeInteger(prefixBuffer, 0x00, largestReference, 8) encoder stream.

   HTTP_QPACK_DECODER_STREAM_ERROR (TBD):  The encoder failed to
      interpret an instruction on the decoder stream.

   Upon encountering an error, an implementation MAY elect to treat it
   as a connection error even if baseIndex >= largestReference:
     encodeInteger(prefixBuffer, 0, baseIndex - largestReference, 7)
   else:
     encodeInteger(prefixBuffer, 0x80,
                   largestReference  - baseIndex, 7)

   return controlBuffer, prefixBuffer + streamBuffer

8. this document prescribes that it MUST
   be treated as a stream error.

7.  Security Considerations

   TBD.

9.

8.  IANA Considerations

9.1.

8.1.  Settings Registration

   This document creates two new settings in the "HTTP/QUIC "HTTP/3 Settings"
   registry established in [QUIC-HTTP]. [HTTP3].

   The entries in the following table are registered by this document.

             +-----------------------+------+---------------+
             | Setting Name          | Code | Specification |
             +-----------------------+------+---------------+
             | HEADER_TABLE_SIZE     | 0x1  | Section 4 5     |
             |                       |      |               |
             | QPACK_BLOCKED_STREAMS | 0x7  | Section 4 5     |
             +-----------------------+------+---------------+

9.2.

8.2.  Stream Type Registration

   This document creates two new settings in the "HTTP/QUIC "HTTP/3 Stream Type"
   registry established in [QUIC-HTTP]. [HTTP3].

   The entries in the following table are registered by this document.

         +----------------------+------+---------------+--------+
         | Stream Type          | Code | Specification | Sender |
         +----------------------+------+---------------+--------+
         | QPACK Encoder Stream | 0x48 | Section 5 4     | Both   |
         |                      |      |               |        |
         | QPACK Decoder Stream | 0x68 | Section 5 4     | Both   |
         +----------------------+------+---------------+--------+

9.3.

8.3.  Error Code Registration

   This document establishes the following new error codes in the "HTTP/
   QUIC
   "HTTP/3 Error Code" registry established in [QUIC-HTTP]. [HTTP3].

   +------------------------------+------+--------------+--------------+
   | Name                         | Code | Description  | Specificatio |
   |                              |      |              | n            |
   +------------------------------+------+--------------+--------------+
   | HTTP_QPACK_DECOMPRESSION_FAI | TBD  | Decompressio | Section 6    |
   | LED                          |      | n of a       |              |
   |                              |      | header block |              |
   |                              |      | failed       |              |
   |                              |      |              |              |
   | HTTP_QPACK_ENCODER_STREAM_ER | TBD  | Error on the | Section 6    |
   | ROR                          |      | encoder      |              |
   |                              |      | stream       |              |
   |                              |      |              |              |
   | HTTP_QPACK_DECODER_STREAM_ER | TBD  | Error on the | Section 6    |
   | ROR                          |      | decoder      |              |
   |                              |      | stream       |              |
   +------------------------------+------+--------------+--------------+

10.

9.  References

10.1.

9.1.  Normative References

   [QUIC-HTTP]

   [HTTP3]    Bishop, M., Ed., "Hypertext Transfer Protocol (HTTP) over
              QUIC", draft-ietf-quic-http-15 Version 3
              (HTTP/3)", draft-ietf-quic-http-16 (work in progress), October
              December 2018.

   [QUIC-TRANSPORT]
              Iyengar, J., Ed. and M. Thomson, Ed., "QUIC: A UDP-Based
              Multiplexed and Secure Transport", draft-ietf-quic-
              transport-14
              transport-16 (work in progress), October December 2018.

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119,
              DOI 10.17487/RFC2119, March 1997,
              <https://www.rfc-editor.org/info/rfc2119>.

   [RFC7541]  Peon, R. and H. Ruellan, "HPACK: Header Compression for
              HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015,
              <https://www.rfc-editor.org/info/rfc7541>.

   [RFC8174]  Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
              2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
              May 2017, <https://www.rfc-editor.org/info/rfc8174>.

10.2.

9.2.  Informative References

   [RFC2360]  Scott, G., "Guide for Internet Standards Writers", BCP 22,
              RFC 2360, DOI 10.17487/RFC2360, June 1998,
              <https://www.rfc-editor.org/info/rfc2360>.

   [RFC7540]  Belshe, M., Peon, R., and M. Thomson, Ed., "Hypertext
              Transfer Protocol Version 2 (HTTP/2)", RFC 7540,
              DOI 10.17487/RFC7540, May 2015,
              <https://www.rfc-editor.org/info/rfc7540>.

10.3.

9.3.  URIs

   [1] https://mailarchive.ietf.org/arch/search/?email_list=quic

   [2] https://github.com/quicwg

   [3] https://github.com/quicwg/base-drafts/labels/-qpack

Appendix A.  Static Table

   +------+-----------------------------+------------------------------+
   | Inde | Name                        | Value                        |
   | x    |                             |                              |
   +------+-----------------------------+------------------------------+
   | 0    | :authority                  |                              |
   |      |                             |                              |
   | 1    | :path                       | /                            |
   |      |                             |                              |
   | 2    | age                         | 0                            |
   |      |                             |                              |
   | 3    | content-disposition         |                              |
   |      |                             |                              |
   | 4    | content-length              | 0                            |
   |      |                             |                              |
   | 5    | cookie                      |                              |
   |      |                             |                              |
   | 6    | date                        |                              |
   |      |                             |                              |
   | 7    | etag                        |                              |
   |      |                             |                              |
   | 8    | if-modified-since           |                              |
   |      |                             |                              |
   | 9    | if-none-match               |                              |
   |      |                             |                              |
   | 10   | last-modified               |                              |
   |      |                             |                              |
   | 11   | link                        |                              |
   |      |                             |                              |
   | 12   | location                    |                              |
   |      |                             |                              |
   | 13   | referer                     |                              |
   |      |                             |                              |
   | 14   | set-cookie                  |                              |
   |      |                             |                              |
   | 15   | :method                     | CONNECT                      |
   |      |                             |                              |
   | 16   | :method                     | DELETE                       |
   |      |                             |                              |
   | 17   | :method                     | GET                          |
   |      |                             |                              |
   | 18   | :method                     | HEAD                         |
   |      |                             |                              |
   | 19   | :method                     | OPTIONS                      |
   |      |                             |                              |
   | 20   | :method                     | POST                         |
   |      |                             |                              |
   | 21   | :method                     | PUT                          |
   |      |                             |                              |
   | 22   | :scheme                     | http                         |
   |      |                             |                              |
   | 23   | :scheme                     | https                        |
   |      |                             |                              |
   | 24   | :status                     | 103                          |
   |      |                             |                              |
   | 25   | :status                     | 200                          |
   |      |                             |                              |
   | 26   | :status                     | 304                          |
   |      |                             |                              |
   | 27   | :status                     | 404                          |
   |      |                             |                              |
   | 28   | :status                     | 503                          |
   |      |                             |                              |
   | 29   | accept                      | */*                          |
   |      |                             |                              |
   | 30   | accept                      | application/dns-message      |
   |      |                             |                              |
   | 31   | accept-encoding             | gzip, deflate, br            |
   |      |                             |                              |
   | 32   | accept-ranges               | bytes                        |
   |      |                             |                              |
   | 33   | access-control-allow-       | cache-control                |
   |      | headers                     |                              |
   |      |                             |                              |
   | 34   | access-control-allow-       | content-type                 |
   |      | headers                     |                              |
   |      |                             |                              |
   | 35   | access-control-allow-origin | *                            |
   |      |                             |                              |
   | 36   | cache-control               | max-age=0                    |
   |      |                             |                              |
   | 37   | cache-control               | max-age=2592000              |
   |      |                             |                              |
   | 38   | cache-control               | max-age=604800               |
   |      |                             |                              |
   | 39   | cache-control               | no-cache                     |
   |      |                             |                              |
   | 40   | cache-control               | no-store                     |
   |      |                             |                              |
   | 41   | cache-control               | public, max-age=31536000     |
   |      |                             |                              |
   | 42   | content-encoding            | br                           |
   |      |                             |                              |
   | 43   | content-encoding            | gzip                         |
   |      |                             |                              |
   | 44   | content-type                | application/dns-message      |
   |      |                             |                              |
   | 45   | content-type                | application/javascript       |
   |      |                             |                              |
   | 46   | content-type                | application/json             |
   |      |                             |                              |
   | 47   | content-type                | application/x-www-form-      |
   |      |                             | urlencoded                   |
   |      |                             |                              |
   | 48   | content-type                | image/gif                    |
   |      |                             |                              |
   | 49   | content-type                | image/jpeg                   |
   |      |                             |                              |
   | 50   | content-type                | image/png                    |
   |      |                             |                              |
   | 51   | content-type                | text/css                     |
   |      |                             |                              |
   | 52   | content-type                | text/html; charset=utf-8     |
   |      |                             |                              |
   | 53   | content-type                | text/plain                   |
   |      |                             |                              |
   | 54   | content-type                | text/plain;charset=utf-8     |
   |      |                             |                              |
   | 55   | range                       | bytes=0-                     |
   |      |                             |                              |
   | 56   | strict-transport-security   | max-age=31536000             |
   |      |                             |                              |
   | 57   | strict-transport-security   | max-age=31536000;            |
   |      |                             | includesubdomains            |
   |      |                             |                              |
   | 58   | strict-transport-security   | max-age=31536000;            |
   |      |                             | includesubdomains; preload   |
   |      |                             |                              |
   | 59   | vary                        | accept-encoding              |
   |      |                             |                              |
   | 60   | vary                        | origin                       |
   |      |                             |                              |
   | 61   | x-content-type-options      | nosniff                      |
   |      |                             |                              |
   | 62   | x-xss-protection            | 1; mode=block                |
   |      |                             |                              |
   | 63   | :status                     | 100                          |
   |      |                             |                              |
   | 64   | :status                     | 204                          |
   |      |                             |                              |
   | 65   | :status                     | 206                          |
   |      |                             |                              |
   | 66   | :status                     | 302                          |
   |      |                             |                              |
   | 67   | :status                     | 400                          |
   |      |                             |                              |
   | 68   | :status                     | 403                          |
   |      |                             |                              |
   | 69   | :status                     | 421                          |
   |      |                             |                              |
   | 70   | :status                     | 425                          |
   |      |                             |                              |
   | 71   | :status                     | 500                          |
   |      |                             |                              |
   | 72   | accept-language             |                              |
   |      |                             |                              |
   | 73   | access-control-allow-       | FALSE                        |
   |      | credentials                 |                              |
   |      |                             |                              |
   | 74   | access-control-allow-       | TRUE                         |
   |      | credentials                 |                              |
   |      |                             |                              |
   | 75   | access-control-allow-       | *                            |
   |      | headers                     |                              |
   |      |                             |                              |
   | 76   | access-control-allow-       | get                          |
   |      | methods                     |                              |
   |      |                             |                              |
   | 77   | access-control-allow-       | get, post, options           |
   |      | methods                     |                              |
   |      |                             |                              |
   | 78   | access-control-allow-       | options                      |
   |      | methods                     |                              |
   |      |                             |                              |
   | 79   | access-control-expose-      | content-length               |
   |      | headers                     |                              |
   |      |                             |                              |
   | 80   | access-control-request-     | content-type                 |
   |      | headers                     |                              |
   |      |                             |                              |
   | 81   | access-control-request-     | get                          |
   |      | method                      |                              |
   |      |                             |                              |
   | 82   | access-control-request-     | post                         |
   |      | method                      |                              |
   |      |                             |                              |
   | 83   | alt-svc                     | clear                        |
   |      |                             |                              |
   | 84   | authorization               |                              |
   |      |                             |                              |
   | 85   | content-security-policy     | script-src 'none'; object-   |
   |      |                             | src 'none'; base-uri 'none'  |
   |      |                             |                              |
   | 86   | early-data                  | 1                            |
   |      |                             |                              |
   | 87   | expect-ct                   |                              |
   |      |                             |                              |
   | 88   | forwarded                   |                              |
   |      |                             |                              |
   | 89   | if-range                    |                              |
   |      |                             |                              |
   | 90   | origin                      |                              |
   |      |                             |                              |
   | 91   | purpose                     | prefetch                     |
   |      |                             |                              |
   | 92   | server                      |                              |
   |      |                             |                              |
   | 93   | timing-allow-origin         | *                            |
   |      |                             |                              |
   | 94   | upgrade-insecure-requests   | 1                            |
   |      |                             |                              |
   | 95   | user-agent                  |                              |
   |      |                             |                              |
   | 96   | x-forwarded-for             |                              |
   |      |                             |                              |
   | 97   | x-frame-options             | deny                         |
   |      |                             |                              |
   | 98   | x-frame-options             | sameorigin                   |
   +------+-----------------------------+------------------------------+

Appendix B.  Sample One Pass Encoding Algorithm

   Pseudo-code for single pass encoding, excluding handling of
   duplicates, non-blocking mode, and reference tracking.

   baseIndex = dynamicTable.baseIndex
   largestReference = 0
   for header in headers:
     staticIdx = staticTable.getIndex(header)
     if staticIdx:
       encodeIndexReference(streamBuffer, staticIdx)
       continue

     dynamicIdx = dynamicTable.getIndex(header)
     if !dynamicIdx:
       # No matching entry.  Either insert+index or encode literal
       nameIdx = getNameIndex(header)
       if shouldIndex(header) and dynamicTable.canIndex(header):
         encodeLiteralWithIncrementalIndex(controlBuffer, nameIdx,
                                           header)
         dynamicTable.add(header)
         dynamicIdx = dynamicTable.baseIndex

     if !dynamicIdx:
       # Couldn't index it, literal
       if nameIdx <= staticTable.size:
         encodeLiteral(streamBuffer, nameIndex, header)
       else:
         # encode literal, possibly with nameIdx above baseIndex
         encodeDynamicLiteral(streamBuffer, nameIndex, baseIndex,
                              header)
         largestReference = max(largestReference,
                                dynamicTable.toAbsolute(nameIdx))
     else:
       # Dynamic index reference
       assert(dynamicIdx)
       largestReference = max(largestReference, dynamicIdx)
       # Encode dynamicIdx, possibly with dynamicIdx above baseIndex
       encodeDynamicIndexReference(streamBuffer, dynamicIdx,
                                   baseIndex)

   # encode the prefix
   encodeInteger(prefixBuffer, 0x00, largestReference, 8)
   if baseIndex >= largestReference:
     encodeInteger(prefixBuffer, 0, baseIndex - largestReference, 7)
   else:
     encodeInteger(prefixBuffer, 0x80,
                   largestReference  - baseIndex, 7)

   return controlBuffer, prefixBuffer + streamBuffer

Appendix C.  Change Log

      *RFC Editor's Note:* Please remove this section prior to
      publication of a final version of this document.

B.1.

C.1.  Since draft-ietf-quic-qpack-03

   Substantial editorial reorganization; no technical changes.

C.2.  Since draft-ietf-quic-qpack-02

   o  Largest Reference encoded modulo MaxEntries (#1763)

   o  New Static Table (#1355)

   o  Table Size Update with Insert Count=0 is a connection error
      (#1762)

   o  Stream Cancellations are optional when
      SETTINGS_HEADER_TABLE_SIZE=0 (#1761)

   o  Implementations must handle 62 bit integers (#1760)

   o  Different error types for each QPACK stream, other changes to
      error handling (#1726)

   o  Preserve header field order (#1725)

   o  Initial table size is the maximum permitted when table is first
      usable (#1642)

B.2.

C.3.  Since draft-ietf-quic-qpack-01

   o  Only header blocks that reference the dynamic table are
      acknowledged (#1603, #1605)

B.3.

C.4.  Since draft-ietf-quic-qpack-00

   o  Renumbered instructions for consistency (#1471, #1472)

   o  Decoder is allowed to validate largest reference (#1404, #1469)

   o  Header block acknowledgments also acknowledge the associated
      largest reference (#1370, #1400)

   o  Added an acknowledgment for unread streams (#1371, #1400)

   o  Removed framing from encoder stream (#1361,#1467)
   o  Control streams use typed unidirectional streams rather than fixed
      stream IDs (#910,#1359)

B.4.

C.5.  Since draft-ietf-quic-qcram-00

   o  Separate instruction sets for table updates and header blocks
      (#1235, #1142, #1141)

   o  Reworked indexing scheme (#1176, #1145, #1136, #1130, #1125,
      #1314)

   o  Added mechanisms that support one-pass encoding (#1138, #1320)

   o  Added a setting to control the number of blocked decoders (#238,
      #1140, #1143)

   o  Moved table updates and acknowledgments to dedicated streams
      (#1121, #1122, #1238)

Acknowledgments

   This draft draws heavily on the text of [RFC7541].  The indirect
   input of those authors is gratefully acknowledged, as well as ideas
   from:

   o  Ryan Hamilton

   o  Patrick McManus

   o  Kazuho Oku

   o  Biren Roy

   o  Ian Swett

   o  Dmitri Tikhonov

   Buck's contribution was supported by Google during his employment
   there.

   A substantial portion of Mike's contribution was supported by
   Microsoft during his employment there.

Authors' Addresses
   Charles 'Buck' Krasic
   Netflix

   Email: ckrasic@netflix.com

   Mike Bishop
   Akamai Technologies

   Email: mbishop@evequefou.be

   Alan Frindell (editor)
   Facebook

   Email: afrind@fb.com