<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.9 -->
<?rfc toc="yes"?>
<?rfc tocindent="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc tocdepth="2"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     docName="draft-ietf-httpbis-header-structure-13"
     ipr="trust200902"
     submissionType="IETF">
   <x:feedback template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title>Structured Headers for HTTP</title>
      <author fullname="Mark Nottingham" initials="M." surname="Nottingham">
         <organization>Fastly</organization>
         <address>
            <email>mnot@mnot.net</email>
            <uri>https://www.mnot.net/</uri>
         </address>
      </author>
      <author fullname="Poul-Henning Kamp" initials="P-H." surname="Kamp">
         <organization>The Varnish Cache Project</organization>
         <address>
            <email>phk@varnish-cache.org</email>
         </address>
      </author>
      <date year="2019" month="August" day="24"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract>
         <t>This document describes a set of data types and associated algorithms that are intended to make it easier and safer to define and handle HTTP header fields. It is intended for use by specifications of new HTTP header fields that wish to use a common syntax that is more restrictive than traditional HTTP field values.</t>
      </abstract>
      <note title="Note to Readers">
         <t>
            <spanx>RFC EDITOR: please remove this section before publication</spanx>
         </t>
         <t>Discussion of this draft takes place on the HTTP working group mailing list (ietf-http-wg@w3.org), which is archived at <eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/">https://lists.w3.org/Archives/Public/ietf-http-wg/</eref>.</t>
         <t>Working Group information can be found at <eref target="https://httpwg.github.io/">https://httpwg.github.io/</eref>; source code and issues list for this draft can be found at <eref target="https://github.com/httpwg/http-extensions/labels/header-structure">https://github.com/httpwg/http-extensions/labels/header-structure</eref>.</t>
         <t>Tests for implementations are collected at <eref target="https://github.com/httpwg/structured-header-tests">https://github.com/httpwg/structured-header-tests</eref>.</t>
         <t>Implementations are tracked at <eref target="https://github.com/httpwg/wiki/wiki/Structured-Headers">https://github.com/httpwg/wiki/wiki/Structured-Headers</eref>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>Specifying the syntax of new HTTP header fields is an onerous task; even with the guidance in <xref target="RFC7231" x:fmt="of" x:sec="8.3.1"/>, there are many decisions – and pitfalls – for a prospective HTTP header field author.</t>
         <t>Once a header field is defined, bespoke parsers and serializers often need to be written, because each header has slightly different handling of what looks like common syntax.</t>
         <t>This document introduces a set of common data structures for use in definitions of new HTTP header field values to address these problems. In particular, it defines a generic, abstract model for header field values, along with a concrete serialisation for expressing that model in textual HTTP <xref target="RFC7230"/> header fields.</t>
         <t>HTTP headers that are defined as “Structured Headers” use the types defined in this specification to define their syntax and basic handling rules, thereby simplifying both their definition by specification writers and handling by implementations.</t>
         <t>Additionally, future versions of HTTP can define alternative serialisations of the abstract model of these structures, allowing headers that use it to be transmitted more efficiently without being redefined.</t>
         <t>Note that it is not a goal of this document to redefine the syntax of existing HTTP headers; the mechanisms described herein are only intended to be used with headers that explicitly opt into them.</t>
         <t>
            <xref target="specify"/> describes how to specify a Structured Header.</t>
         <t>
            <xref target="types"/> defines a number of abstract data types that can be used in Structured Headers. Those abstract types can be serialized into and parsed from textual HTTP headers using the algorithms described in <xref target="text"/>.</t>
         <section anchor="strict" title="Intentionally Strict Processing">
            <t>This specification intentionally defines strict parsing and serialisation behaviours using step-by-step algorithms; the only error handling defined is to fail the operation altogether.</t>
            <t>It is designed to encourage faithful implementation and therefore good interoperability. Therefore, an implementation that tried to be “helpful” by being more tolerant of input would make interoperability worse, since that would create pressure on other implementations to implement similar (but likely subtly different) workarounds.</t>
            <t>In other words, strict processing is an intentional feature of this specification; it allows non-conformant input to be discovered and corrected by the producer early, and avoids both interoperability and security issues that might otherwise result.</t>
            <t>Note that as a result of this strictness, if a header field is appended to by multiple parties (e.g., intermediaries, or different components in the sender), an error in one party’s value is likely to cause the entire header field to fail parsing.</t>
         </section>
         <section anchor="notational-conventions" title="Notational Conventions">
            <t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/>
               <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
            <t>This document uses algorithms to specify parsing and serialisation behaviours, and the Augmented Backus-Naur Form (ABNF) notation of <xref target="RFC5234"/> to illustrate expected syntax in textual HTTP header fields. In doing so, uses the VCHAR, SP, DIGIT, ALPHA and DQUOTE rules from <xref target="RFC5234"/>. It also includes the OWS rule from <xref target="RFC7230"/>.</t>
            <t>When parsing from textual HTTP header fields, implementations MUST follow the algorithms, but MAY vary in implementation so as the behaviours are indistinguishable from specified behaviour. If there is disagreement between the parsing algorithms and ABNF, the specified algorithms take precedence. In some places, the algorithms are “greedy” with whitespace, but this should not affect conformance.</t>
            <t>For serialisation to textual header fields, the ABNF illustrates the range of acceptable wire representations with as much fidelity as possible, and the algorithms define the recommended way to produce them. Implementations MAY vary from the specified behaviour so long as the output still matches the ABNF.</t>
         </section>
      </section>
      <section anchor="specify" title="Defining New Structured Headers">
         <t>To define a HTTP header as a structured header, its specification needs to:</t>
         <t>
            <list style="symbols">
               <t>Reference this specification. Recipients and generators of the header need to know that the requirements of this document are in effect.</t>
               <t>Specify the header field’s allowed syntax for values, in terms of the types described in <xref target="types"/>, along with their associated semantics. Syntax definitions are encouraged to use the ABNF rules beginning with “sh-“ defined in this specification; other rules in this specification are not intended for use outside it.</t>
               <t>Specify any additional constraints upon the syntax of the structures used, as well as the consequences when those constraints are violated. When Structured Headers parsing fails, the header is ignored (see <xref target="text-parse"/>); in most situations, header-specific constraints should do likewise.</t>
            </list>
         </t>
         <t>Note that a header field definition cannot relax the requirements of this specification because doing so would preclude handling by generic software; they can only add additional constraints (for example, on the numeric range of integers and floats, the format of strings and tokens, the types allowed in a dictionary’s values, or the number of items in a list). Likewise, header field definitions can only use Structured Headers for the entire header field value, not a portion thereof.</t>
         <t>This specification defines minimums for the length or number of various structures supported by Structured Headers implementations. It does not specify maximum sizes in most cases, but header authors should be aware that HTTP implementations do impose various limits on the size of individual header fields, the total number of fields, and/or the size of the entire header block.</t>
         <t>For example, a fictitious Foo-Example header field might be specified as:</t>
         <figure>
            <artwork type="example">
42. Foo-Example Header

The Foo-Example HTTP header field conveys information about how
much Foo the message has.

Foo-Example is a Structured Header [RFCxxxx]. Its value MUST be a
dictionary (Section Y.Y of [RFCxxxx]). Its ABNF is:

  Foo-Example = sh-dictionary

The dictionary MUST contain:

* Exactly one member whose name is "foo", and whose value is an
  integer (Section Y.Y of [RFCxxxx]), indicating the number of foos
  in the message.
* Exactly one member whose name is "barUrl", and whose value is a
  list of strings (Section Y.Y of [RFCxxxx]), conveying the Bar URLs
  for the message. See below for processing requirements.

If the parsed header field does not contain both, it MUST be
ignored.

"foo" MUST be between 0 and 10, inclusive; other values MUST cause
the header to be ignored.

"barUrl" contains one or more URI-references (Section 4.1 of
[RFC3986], Section 4.1). If barURL is not a valid URI-reference,
it MUST be ignored. If barURL is a relative reference (Section 4.2
of [RFC3986]), it MUST be resolved (Section 5 of [RFC3986]) before
being used.

For example:

  Foo-Example: foo=2, barUrl=("https://bar.example.com/")
</artwork>
         </figure>
      </section>
      <section anchor="types" title="Structured Header Data Types">
         <t>This section defines the abstract value types that can be composed into Structured Headers. The ABNF provided represents the on-wire format in textual HTTP headers.</t>
         <section anchor="list" title="Lists">
            <t>Lists are arrays of zero or more members, each of which can be an item (<xref target="item"/>) or an inner list (an array of zero or more items).</t>
            <t>Each member of the top-level list can also have associated parameters – an ordered map of key-value pairs where the keys are short, textual strings and the values are items (<xref target="item"/>). There can be zero or more parameters on a member, and their keys are required to be unique within that scope.</t>
            <t>The ABNF for lists is:</t>
            <figure>
               <artwork type="abnf">
sh-list       = list-member *( OWS "," OWS list-member )
list-member   = ( sh-item / inner-list ) *parameter
inner-list    = "(" OWS [ sh-item *( SP sh-item ) OWS ] ")"
parameter     = OWS ";" OWS param-name [ "=" param-value ]
param-name    = key
key           = lcalpha *( lcalpha / DIGIT / "_" / "-" / "*" )
lcalpha       = %x61-7A ; a-z
param-value   = sh-item
</artwork>
            </figure>
            <t>In textual HTTP headers, each member is separated by a comma and optional whitespace. For example, a header field whose value is defined as a list of strings could look like:</t>
            <figure>
               <artwork type="example">
Example-StrListHeader: "foo", "bar", "It was the best of times."
</artwork>
            </figure>
            <t>In textual HTTP headers, inner lists are denoted by surrounding parenthesis, and have their values delimited by a single space. A header field whose value is defined as a list of lists of strings could look like:</t>
            <figure>
               <artwork type="example">
Example-StrListListHeader: ("foo" "bar"), ("baz"), ("bat" "one"), ()
</artwork>
            </figure>
            <t>Note that the last member in this example is an empty inner list.</t>
            <t>In textual HTTP headers, members’ parameters are separated from the member and each other by semicolons. For example:</t>
            <figure>
               <artwork type="example">
Example-ParamListHeader: abc;a=1;b=2; cde_456, (ghi jkl);q="9";r=w
</artwork>
            </figure>
            <t>In textual HTTP headers, an empty list is denoted by not serialising the header at all.</t>
            <t>Parsers MUST support lists containing at least 1024 members, support members with at least 256 parameters, support inner-lists containing at least 256 members, and support parameter keys with at least 64 characters.</t>
            <t>Header specifications can constrain the types of individual list values (including that of individual inner-list members and parameters) if necessary.</t>
         </section>
         <section anchor="dictionary" title="Dictionaries">
            <t>Dictionaries are ordered maps of name-value pairs, where the names are short, textual strings and the values are items (<xref target="item"/>) or arrays of items. There can be zero or more members, and their names are required to be unique within the scope of the dictionary they occur within.</t>
            <t>Each member of the dictionary can also have associated parameters – an ordered map of key-value pairs where the keys are short, textual strings and the values are items (<xref target="item"/>). There can be zero or more parameters on a member, and their keys are required to be unique within that scope.</t>
            <t>Implementations MUST provide access to dictionaries both by index and by name. Specifications MAY use either means of accessing the members.</t>
            <t>The ABNF for dictionaries in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-dictionary  = dict-member *( OWS "," OWS dict-member )
dict-member    = member-name "=" member-value *parameter
member-name    = key
member-value   = sh-item / inner-list
</artwork>
            </figure>
            <t>In textual HTTP headers, members are separated by a comma with optional whitespace, while names and values are separated by “=” (without whitespace). For example:</t>
            <figure>
               <artwork type="example">
Example-DictHeader: en="Applepie", da=*w4ZibGV0w6ZydGU=*
</artwork>
            </figure>
            <t>A dictionary with a member whose value is an inner-list of tokens:</t>
            <figure>
               <artwork type="example">
Example-DictListHeader: rating=1.5, feelings=(joy sadness)
</artwork>
            </figure>
            <t>A dictionary with a mix of singular and list values, some with parameters:</t>
            <figure>
               <artwork type="example">
Example-MixDict: a=(1,2), b=3, c=4;aa=bb, d=(5,6);valid=?T
</artwork>
            </figure>
            <t>As with lists, an empty dictionary is represented in textual HTTP headers by omitting the entire header field.</t>
            <t>Typically, a header field specification will define the semantics using individual member names, as well as whether their presence is required or optional. Recipients MUST ignore names that are undefined or unknown, unless the header field’s specification specifically disallows them.</t>
            <t>Parsers MUST support dictionaries containing at least 1024 name/value pairs, and names with at least 64 characters.</t>
         </section>
         <section anchor="item" title="Items">
            <t>An item is can be a integer (<xref target="integer"/>), float (<xref target="float"/>), string (<xref target="string"/>), token (<xref target="token"/>), byte sequence (<xref target="binary"/>), or Boolean (<xref target="boolean"/>).</t>
            <t>The ABNF for items in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-item = sh-integer / sh-float / sh-string / sh-token / sh-binary
          / sh-boolean
</artwork>
            </figure>
         </section>
         <section anchor="integer" title="Integers">
            <t>Integers have a range of −999,999,999,999,999 to 999,999,999,999,999 inclusive (i.e., up to fifteen digits, signed), for IEEE 754 compatibility (<xref target="IEEE754"/>).</t>
            <t>The ABNF for integers in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-integer = ["-"] 1*15DIGIT
</artwork>
            </figure>
            <t>For example:</t>
            <figure>
               <artwork type="example">
Example-IntegerHeader: 42
</artwork>
            </figure>
            <t>Note that commas in integers are used in this section’s prose only for readability; they are not valid in the wire format.</t>
         </section>
         <section anchor="float" title="Floats">
            <t>Floats are decimal numbers with an integer and a fractional component. The fractional component has at most six digits of precision. Additionally, like integers, it can have no more than fifteen digits in total, which in some cases further constrains its precision.</t>
            <t>The ABNF for floats in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-float    = ["-"] (1*9DIGIT "." 1*6DIGIT /
                      10DIGIT "." 1*5DIGIT /
                      11DIGIT "." 1*4DIGIT /
                      12DIGIT "." 1*3DIGIT /
                      13DIGIT "." 1*2DIGIT /
                      14DIGIT "." 1DIGIT )
</artwork>
            </figure>
            <t>For example, a header whose value is defined as a float could look like:</t>
            <figure>
               <artwork type="example">
Example-FloatHeader: 4.5
</artwork>
            </figure>
         </section>
         <section anchor="string" title="Strings">
            <t>Strings are zero or more printable ASCII <xref target="RFC0020"/> characters (i.e., the range 0x20 to 0x7E). Note that this excludes tabs, newlines, carriage returns, etc.</t>
            <t>The ABNF for strings in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-string = DQUOTE *(chr) DQUOTE
chr       = unescaped / escaped
unescaped = %x20-21 / %x23-5B / %x5D-7E
escaped   = "\" ( DQUOTE / "\" )
</artwork>
            </figure>
            <t>In textual HTTP headers, strings are delimited with double quotes, using a backslash (“\”) to escape double quotes and backslashes. For example:</t>
            <figure>
               <artwork type="example">
Example-StringHeader: "hello world"
</artwork>
            </figure>
            <t>Note that strings only use DQUOTE as a delimiter; single quotes do not delimit strings. Furthermore, only DQUOTE and “\” can be escaped; other sequences MUST cause parsing to fail.</t>
            <t>Unicode is not directly supported in this document, because it causes a number of interoperability issues, and – with few exceptions – header values do not require it.</t>
            <t>When it is necessary for a field value to convey non-ASCII string content, a byte sequence (<xref target="binary"/>) SHOULD be specified, along with a character encoding (preferably UTF-8).</t>
            <t>Parsers MUST support strings with at least 1024 characters.</t>
         </section>
         <section anchor="token" title="Tokens">
            <t>Tokens are short textual words; their abstract model is identical to their expression in the textual HTTP serialisation.</t>
            <t>The ABNF for tokens in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-token = ALPHA
           *( ALPHA / DIGIT / "_" / "-" / "." / ":" / "%"
              / "*" / "/" )
</artwork>
            </figure>
            <t>Parsers MUST support tokens with at least 512 characters.</t>
            <t>Note that a Structured Header token is not the same as the “token” ABNF rule defined in <xref target="RFC7230"/>.</t>
         </section>
         <section anchor="binary" title="Byte Sequences">
            <t>Byte sequences can be conveyed in Structured Headers.</t>
            <t>The ABNF for a byte sequence in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-binary = "*" *(base64) "*"
base64    = ALPHA / DIGIT / "+" / "/" / "="
</artwork>
            </figure>
            <t>In textual HTTP headers, a byte sequence is delimited with asterisks and encoded using base64 (<xref target="RFC4648" x:fmt="," x:sec="4"/>). For example:</t>
            <figure>
               <artwork type="example">
Example-BinaryHdr: *cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==*
</artwork>
            </figure>
            <t>Parsers MUST support byte sequences with at least 16384 octets after decoding.</t>
         </section>
         <section anchor="boolean" title="Booleans">
            <t>Boolean values can be conveyed in Structured Headers.</t>
            <t>The ABNF for a Boolean in textual HTTP headers is:</t>
            <figure>
               <artwork type="abnf">
sh-boolean = "?" boolean
boolean    = "0" / "1"
</artwork>
            </figure>
            <t>In textual HTTP headers, a boolean is indicated with a leading “?” character. For example:</t>
            <figure>
               <artwork type="example">
Example-BoolHdr: ?1
</artwork>
            </figure>
         </section>
      </section>
      <section anchor="text"
               title="Working With Structured Headers in Textual HTTP Headers">
         <t>This section defines how to serialize and parse Structured Headers in textual header fields, and protocols compatible with them (e.g., in HTTP/2 <xref target="RFC7540"/> before HPACK <xref target="RFC7541"/> is applied).</t>
         <section anchor="text-serialize" title="Serializing Structured Headers">
            <t>Given a structure defined in this specification, return an ASCII string suitable for use in a textual HTTP header value.</t>
            <t>
               <list style="numbers">
                  <t>If the structure is a dictionary or list and its value is empty (i.e., it has no members), do not send the serialize field at all (i.e., omit both the field-name and field-value).</t>
                  <t>If the structure is a dictionary, let output_string be the result of Serializing a Dictionary (<xref target="ser-dictionary"/>).</t>
                  <t>Else if the structure is a list, let output_string be the result of Serializing a List (<xref target="ser-list"/>).</t>
                  <t>Else if the structure is an item, let output_string be the result of Serializing an Item (<xref target="ser-item"/>).</t>
                  <t>Else, fail serialisation.</t>
                  <t>Return output_string converted into an array of bytes, using ASCII encoding <xref target="RFC0020"/>.</t>
               </list>
            </t>
            <section anchor="ser-list" title="Serializing a List">
               <t>Given a list of (member-value, parameters) as input_list, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>Let output be an empty string.</t>
                     <t>For each (member-value, parameters) of input_list: <list style="numbers">
                           <t>If member-value is an array, append the result of applying Serialising an Inner List (<xref target="ser-innerlist"/>) with member-value to output.</t>
                           <t>Otherwise, append the result of applying Serializing an Item (<xref target="ser-item"/>) with member-value to output.</t>
                           <t>Append the result of Serializing Parameters <xref target="ser-params"/> with parameters to output.</t>
                           <t>If more member-values remain in input_plist: <list style="numbers">
                                 <t>Append a COMMA to output.</t>
                                 <t>Append a single WS to output.</t>
                              </list>
                           </t>
                        </list>
                     </t>
                     <t>Return output.</t>
                  </list>
               </t>
               <section anchor="ser-innerlist" title="Serialising an Inner List">
                  <t>Given an array as inner_list, return an ASCII string suitable for use in a textual HTTP header value.</t>
                  <t>
                     <list style="numbers">
                        <t>Let output be the string “(“.</t>
                        <t>For each member-value of inner_list: <list style="numbers">
                              <t>Append the result of applying Serializing an Item (<xref target="ser-item"/>) with member-value to output.</t>
                              <t>If inner_list is not empty, append a single WS to output.</t>
                           </list>
                        </t>
                        <t>Append “)” to output.</t>
                        <t>Return output.</t>
                     </list>
                  </t>
               </section>
               <section anchor="ser-params" title="Serializing Parameters">
                  <t>Given an ordered dictionary as input_parameters (each member having a param-name and a param-value), return an ASCII string suitable for use in a textual HTTP header value.</t>
                  <t>
                     <list style="numbers">
                        <t>Let output be an empty string.</t>
                        <t>For each parameter-name with a value of param-value in input_parameters: <list style="numbers">
                              <t>Append “;” to output.</t>
                              <t>Append the result of applying Serializing a Key (<xref target="ser-key"/>) with param-name to output.</t>
                              <t>If param-value is not null: <list style="numbers">
                                    <t>Append “=” to output.</t>
                                    <t>Append the result of applying Serializing an Item (<xref target="ser-item"/>) with param-value to output.</t>
                                 </list>
                              </t>
                           </list>
                        </t>
                        <t>Return output.</t>
                     </list>
                  </t>
               </section>
               <section anchor="ser-key" title="Serializing a Key">
                  <t>Given a key as input_key, return an ASCII string suitable for use in a textual HTTP header value.</t>
                  <t>
                     <list style="numbers">
                        <t>If input_key is not a sequence of characters, or contains characters not in lcalpha, DIGIT, “*”, “_”, or “-“, fail serialisation.</t>
                        <t>Let output be an empty string.</t>
                        <t>Append input_key to output.</t>
                        <t>Return output.</t>
                     </list>
                  </t>
               </section>
            </section>
            <section anchor="ser-dictionary" title="Serializing a Dictionary">
               <t>Given an ordered dictionary as input_dictionary (each member having a member-name and a tuple value of (member-value, parameters)), return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>Let output be an empty string.</t>
                     <t>For each member-name with a value of (member-value, parameters) in input_dictionary: <list style="numbers">
                           <t>Append the result of applying Serializing a Key (<xref target="ser-key"/>) with member’s member-name to output.</t>
                           <t>Append “=” to output.</t>
                           <t>If member-value is an array, append the result of applying Serialising an Inner List (<xref target="ser-innerlist"/>) with member-value to output.</t>
                           <t>Otherwise, append the result of applying Serializing an Item (<xref target="ser-item"/>) with member-value to output.</t>
                           <t>Append the result of Serializing Parameters <xref target="ser-params"/> with parameters to output.</t>
                           <t>If more members remain in input_dictionary: <list style="numbers">
                                 <t>Append a COMMA to output.</t>
                                 <t>Append a single WS to output.</t>
                              </list>
                           </t>
                        </list>
                     </t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-item" title="Serializing an Item">
               <t>Given an item as input_item, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_item is an integer, return the result of applying Serializing an Integer (<xref target="ser-integer"/>) to input_item.</t>
                     <t>If input_item is a float, return the result of applying Serializing a Float (<xref target="ser-float"/>) to input_item.</t>
                     <t>If input_item is a string, return the result of applying Serializing a String (<xref target="ser-string"/>) to input_item.</t>
                     <t>If input_item is a token, return the result of Serializing a Token (<xref target="ser-token"/>) to input_item.</t>
                     <t>If input_item is a Boolean, return the result of applying Serializing a Boolean (<xref target="ser-boolean"/>) to input_item.</t>
                     <t>If input_item is a byte sequence, return the result of applying Serializing a Byte Sequence (<xref target="ser-binary"/>) to input_item.</t>
                     <t>Otherwise, fail serialisation.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-integer" title="Serializing an Integer">
               <t>Given an integer as input_integer, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_integer is not an integer in the range of −999,999,999,999,999 to 999,999,999,999,999 inclusive, fail serialisation.</t>
                     <t>Let output be an empty string.</t>
                     <t>If input_integer is less than (but not equal to) 0, append “-“ to output.</t>
                     <t>Append input_integer’s numeric value represented in base 10 using only decimal digits to output.</t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-float" title="Serializing a Float">
               <t>Given a float as input_float, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>Let output be an empty string.</t>
                     <t>If input_float is less than (but not equal to) 0, append “-“ to output.</t>
                     <t>Append input_float’s integer component represented in base 10 (using only decimal digits) to output; if it is zero, append “0”.</t>
                     <t>Let integer_digits be the number of characters appended in the previous step.</t>
                     <t>If integer_digits is greater than 14, fail serialisation.</t>
                     <t>Let digits_avail be 15 minus integer_digits.</t>
                     <t>Let fractional_digits_avail be the minimum of digits_avail and 6.</t>
                     <t>Append “.” to output.</t>
                     <t>Append at most fractional_digits_avail digits of input_float’s fractional component represented in base 10 to output (using only decimal digits, and truncating any remaining digits); if it is zero, append “0”.</t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-string" title="Serializing a String">
               <t>Given a string as input_string, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_string is not a sequence of characters, or contains characters outside the range %x00-1f or %x7f (i.e., is not in VCHAR or SP), fail serialisation.</t>
                     <t>Let output be an empty string.</t>
                     <t>Append DQUOTE to output.</t>
                     <t>For each character char in input_string: <list style="numbers">
                           <t>If char is “\” or DQUOTE: <list style="numbers">
                                 <t>Append “\” to output.</t>
                              </list>
                           </t>
                           <t>Append char to output.</t>
                        </list>
                     </t>
                     <t>Append DQUOTE to output.</t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-token" title="Serializing a Token">
               <t>Given a token as input_token, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_token is not a sequence of characters, or contains characters not in ALPHA, DIGIT, “_”, “-“, “.”, “:”, “%”, “*” or “/”, fail serialisation.</t>
                     <t>Let output be an empty string.</t>
                     <t>Append input_token to output.</t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
            <section anchor="ser-binary" title="Serializing a Byte Sequence">
               <t>Given a byte sequence as input_bytes, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_bytes is not a sequence of bytes, fail serialisation.</t>
                     <t>Let output be an empty string.</t>
                     <t>Append “*” to output.</t>
                     <t>Append the result of base64-encoding input_bytes as per <xref target="RFC4648" x:fmt="," x:sec="4"/>, taking account of the requirements below.</t>
                     <t>Append “*” to output.</t>
                     <t>Return output.</t>
                  </list>
               </t>
               <t>The encoded data is required to be padded with “=”, as per <xref target="RFC4648" x:fmt="," x:sec="3.2"/>.</t>
               <t>Likewise, encoded data SHOULD have pad bits set to zero, as per <xref target="RFC4648" x:fmt="," x:sec="3.5"/>, unless it is not possible to do so due to implementation constraints.</t>
            </section>
            <section anchor="ser-boolean" title="Serializing a Boolean">
               <t>Given a Boolean as input_boolean, return an ASCII string suitable for use in a textual HTTP header value.</t>
               <t>
                  <list style="numbers">
                     <t>If input_boolean is not a boolean, fail serialisation.</t>
                     <t>Let output be an empty string.</t>
                     <t>Append “?” to output.</t>
                     <t>If input_boolean is true, append “1” to output.</t>
                     <t>If input_boolean is false, append “0” to output.</t>
                     <t>Return output.</t>
                  </list>
               </t>
            </section>
         </section>
         <section anchor="text-parse"
                  title="Parsing Header Fields into Structured Headers">
            <t>When a receiving implementation parses textual HTTP header fields that are known to be Structured Headers, it is important that care be taken, as there are a number of edge cases that can cause interoperability or even security problems. This section specifies the algorithm for doing so.</t>
            <t>Given an array of bytes input_bytes that represents the chosen header’s field-value (which is an empty string if that header is not present), and header_type (one of “dictionary”, “list”, or “item”), return the parsed header value.</t>
            <t>
               <list style="numbers">
                  <t>Convert input_bytes into an ASCII string input_string; if conversion fails, fail parsing.</t>
                  <t>Discard any leading OWS from input_string.</t>
                  <t>If header_type is “list”, let output be the result of Parsing a List from Text (<xref target="parse-list"/>).</t>
                  <t>If header_type is “dictionary”, let output be the result of Parsing a Dictionary from Text (<xref target="parse-dictionary"/>).</t>
                  <t>If header_type is “item”, let output be the result of Parsing an Item from Text (<xref target="parse-item"/>).</t>
                  <t>Discard any leading OWS from input_string.</t>
                  <t>If input_string is not empty, fail parsing.</t>
                  <t>Otherwise, return output.</t>
               </list>
            </t>
            <t>When generating input_bytes, parsers MUST combine all instances of the target header field into one comma-separated field-value, as per <xref target="RFC7230" x:fmt="," x:sec="3.2.2"/>; this assures that the header is processed correctly.</t>
            <t>For Lists and Dictionaries, this has the effect of correctly concatenating all instances of the header field, as long as individual individual members of the top-level data structure are not split across multiple header instances.</t>
            <t>Strings split across multiple header instances will have unpredictable results, because comma(s) and whitespace inserted upon combination will become part of the string output by the parser. Since concatenation might be done by an upstream intermediary, the results are not under the control of the serializer or the parser.</t>
            <t>Tokens, Integers, Floats and Byte Sequences cannot be split across multiple headers because the inserted commas will cause parsing to fail.</t>
            <t>If parsing fails – including when calling another algorithm – the entire header field’s value MUST be ignored (i.e., treated as if the header field were not present in the message). This is intentionally strict, to improve interoperability and safety, and specifications referencing this document are not allowed to loosen this requirement.</t>
            <t>Note that this requirement does not apply to an implementation that is not parsing the header field; for example, an intermediary is not required to strip a failing header field from a message before forwarding it.</t>
            <section anchor="parse-list" title="Parsing a List from Text">
               <t>Given an ASCII string as input_string, return an array of (member, parameters). input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>Let members be an empty array.</t>
                     <t>While input_string is not empty: <list style="numbers">
                           <t>Let member be the result of running Parsing a Parameterized Member from Text (<xref target="parse-param"/>) with input_string.</t>
                           <t>Append member to members.</t>
                           <t>Discard any leading OWS from input_string.</t>
                           <t>If input_string is empty, return members.</t>
                           <t>Consume the first character of input_string; if it is not COMMA, fail parsing.</t>
                           <t>Discard any leading OWS from input_string.</t>
                           <t>If input_string is empty, there is a trailing comma; fail parsing.</t>
                        </list>
                     </t>
                     <t>No structured data has been found; return members (which is empty).</t>
                  </list>
               </t>
               <section anchor="parse-param" title="Parsing a Parameterized Member from Text">
                  <t>Given an ASCII string as input_string, return a member (either a list of items, or a single item) with an ordered map of parameters. input_string is modified to remove the parsed value.</t>
                  <t>
                     <list style="numbers">
                        <t>If the first character of input_string is “(“, let member be the result of running Parsing an Inner List (<xref target="parse-innerlist"/>) with input_string.</t>
                        <t>Else, let member be the result of running Parsing an Item (<xref target="parse-item"/>) with input_string.</t>
                        <t>Let parameters be an empty, ordered map.</t>
                        <t>While input_string is not empty: <list style="numbers">
                              <t>Discard any leading OWS from input_string.</t>
                              <t>If the first character of input_string is not “;”, exit the loop.</t>
                              <t>Consume a “;” character from the beginning of input_string.</t>
                              <t>Discard any leading OWS from input_string.</t>
                              <t>let param_name be the result of Parsing a key from Text (<xref target="parse-key"/>) from input_string.</t>
                              <t>If param_name is already present in parameters, there is a duplicate; fail parsing.</t>
                              <t>Let param_value be a null value.</t>
                              <t>If the first character of input_string is “=”: <list style="numbers">
                                    <t>Consume the “=” character at the beginning of input_string.</t>
                                    <t>Let param_value be the result of Parsing an Item from Text (<xref target="parse-item"/>) from input_string.</t>
                                 </list>
                              </t>
                              <t>Append key param_name with value param_value to parameters.</t>
                           </list>
                        </t>
                        <t>Return the tuple (member, parameters).</t>
                     </list>
                  </t>
               </section>
               <section anchor="parse-innerlist" title="Parsing an Inner List">
                  <t>Given an ASCII string as input_string, return an array of items. input_string is modified to remove the parsed value.</t>
                  <t>
                     <list style="numbers">
                        <t>Consume the first character of input_string; if it is not “(“, fail parsing.</t>
                        <t>Let inner_list be an empty array.</t>
                        <t>While input_string is not empty: <list style="numbers">
                              <t>Discard any leading OWS from input_string.</t>
                              <t>If the first character of input_string is “)”: <list style="numbers">
                                    <t>Consume the first character of input_string.</t>
                                    <t>Return inner_list.</t>
                                 </list>
                              </t>
                              <t>Let item be the result of running Parsing an Item from Text (<xref target="parse-item"/>) with input_string.</t>
                              <t>Append item to inner_list.</t>
                              <t>If the first character of input_string is not SP or “)”, fail parsing.</t>
                           </list>
                        </t>
                        <t>The end of the inner list was not found; fail parsing.</t>
                     </list>
                  </t>
               </section>
               <section anchor="parse-key" title="Parsing a Key from Text">
                  <t>Given an ASCII string as input_string, return a key. input_string is modified to remove the parsed value.</t>
                  <t>
                     <list style="numbers">
                        <t>If the first character of input_string is not lcalpha, fail parsing.</t>
                        <t>Let output_string be an empty string.</t>
                        <t>While input_string is not empty: <list style="numbers">
                              <t>If the first character of input_string is not one of lcalpha, DIGIT, “*”, “_”, or “-“, return output_string.</t>
                              <t>Let char be the result of removing the first character of input_string.</t>
                              <t>Append char to output_string.</t>
                           </list>
                        </t>
                        <t>Return output_string.</t>
                     </list>
                  </t>
               </section>
            </section>
            <section anchor="parse-dictionary" title="Parsing a Dictionary from Text">
               <t>Given an ASCII string as input_string, return an ordered map of (key, item). input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>Let dictionary be an empty, ordered map.</t>
                     <t>While input_string is not empty: <list style="numbers">
                           <t>Let this_key be the result of running Parsing a Key from Text (<xref target="parse-key"/>) with input_string.</t>
                           <t>If dictionary already contains the name this_key, there is a duplicate; fail parsing.</t>
                           <t>Consume the first character of input_string; if it is not “=”, fail parsing.</t>
                           <t>Let member be the result of running Parsing a Parameterized Member from Text (<xref target="parse-param"/>) with input_string.</t>
                           <t>Add name this_key with value member to dictionary.</t>
                           <t>Discard any leading OWS from input_string.</t>
                           <t>If input_string is empty, return dictionary.</t>
                           <t>Consume the first character of input_string; if it is not COMMA, fail parsing.</t>
                           <t>Discard any leading OWS from input_string.</t>
                           <t>If input_string is empty, there is a trailing comma; fail parsing.</t>
                        </list>
                     </t>
                     <t>No structured data has been found; return dictionary (which is empty).</t>
                  </list>
               </t>
            </section>
            <section anchor="parse-item" title="Parsing an Item from Text">
               <t>Given an ASCII string as input_string, return an item. input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>If the first character of input_string is a “-“ or a DIGIT, process input_string as a number (<xref target="parse-number"/>) and return the result.</t>
                     <t>If the first character of input_string is a DQUOTE, process input_string as a string (<xref target="parse-string"/>) and return the result.</t>
                     <t>If the first character of input_string is “*”, process input_string as a byte sequence (<xref target="parse-binary"/>) and return the result.</t>
                     <t>If the first character of input_string is “?”, process input_string as a Boolean (<xref target="parse-boolean"/>) and return the result.</t>
                     <t>If the first character of input_string is an ALPHA, process input_string as a token (<xref target="parse-token"/>) and return the result.</t>
                     <t>Otherwise, the item type is unrecognized; fail parsing.</t>
                  </list>
               </t>
            </section>
            <section anchor="parse-number" title="Parsing a Number from Text">
               <t>Given an ASCII string as input_string, return a number. input_string is modified to remove the parsed value.</t>
               <t>NOTE: This algorithm parses both Integers (<xref target="integer"/>) and Floats (<xref target="float"/>), and returns the corresponding structure.</t>
               <t>
                  <list style="numbers">
                     <t>Let type be “integer”.</t>
                     <t>Let sign be 1.</t>
                     <t>Let input_number be an empty string.</t>
                     <t>If the first character of input_string is “-“, consume it and set sign to -1.</t>
                     <t>If input_string is empty, there is an empty integer; fail parsing.</t>
                     <t>If the first character of input_string is not a DIGIT, fail parsing.</t>
                     <t>While input_string is not empty: <list style="numbers">
                           <t>Let char be the result of consuming the first character of input_string.</t>
                           <t>If char is a DIGIT, append it to input_number.</t>
                           <t>Else, if type is “integer” and char is “.”, append char to input_number and set type to “float”.</t>
                           <t>Otherwise, prepend char to input_string, and exit the loop.</t>
                           <t>If type is “integer” and input_number contains more than 15 characters, fail parsing.</t>
                           <t>If type is “float” and input_number contains more than 16 characters, fail parsing.</t>
                        </list>
                     </t>
                     <t>If type is “integer”: <list style="numbers">
                           <t>Parse input_number as an integer and let output_number be the product of the result and sign.</t>
                           <t>If output_number is outside the range defined in <xref target="integer"/>, fail parsing.</t>
                        </list>
                     </t>
                     <t>Otherwise: <list style="numbers">
                           <t>If the final character of input_number is “.”, fail parsing.</t>
                           <t>If the number of characters after “.” in input_number is greater than six, fail parsing.</t>
                           <t>Parse input_number as a float and let output_number be the product of the result and sign.</t>
                        </list>
                     </t>
                     <t>Return output_number.</t>
                  </list>
               </t>
            </section>
            <section anchor="parse-string" title="Parsing a String from Text">
               <t>Given an ASCII string as input_string, return an unquoted string. input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>Let output_string be an empty string.</t>
                     <t>If the first character of input_string is not DQUOTE, fail parsing.</t>
                     <t>Discard the first character of input_string.</t>
                     <t>While input_string is not empty: <list style="numbers">
                           <t>Let char be the result of consuming the first character of input_string.</t>
                           <t>If char is a backslash (“\”): <list style="numbers">
                                 <t>If input_string is now empty, fail parsing.</t>
                                 <t>Let next_char be the result of consuming the first character of input_string.</t>
                                 <t>If next_char is not DQUOTE or “\”, fail parsing.</t>
                                 <t>Append next_char to output_string.</t>
                              </list>
                           </t>
                           <t>Else, if char is DQUOTE, return output_string.</t>
                           <t>Else, if char is in the range %x00-1f or %x7f (i.e., is not in VCHAR or SP), fail parsing.</t>
                           <t>Else, append char to output_string.</t>
                        </list>
                     </t>
                     <t>Reached the end of input_string without finding a closing DQUOTE; fail parsing.</t>
                  </list>
               </t>
            </section>
            <section anchor="parse-token" title="Parsing a Token from Text">
               <t>Given an ASCII string as input_string, return a token. input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>If the first character of input_string is not ALPHA, fail parsing.</t>
                     <t>Let output_string be an empty string.</t>
                     <t>While input_string is not empty: <list style="numbers">
                           <t>If the first character of input_string is not one of ALPHA, DIGIT, “_”, “-“, “.”, “:”, “%”, “*” or “/”, return output_string.</t>
                           <t>Let char be the result of consuming the first character of input_string.</t>
                           <t>Append char to output_string.</t>
                        </list>
                     </t>
                     <t>Return output_string.</t>
                  </list>
               </t>
            </section>
            <section anchor="parse-binary" title="Parsing a Byte Sequence from Text">
               <t>Given an ASCII string as input_string, return a byte sequence. input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>If the first character of input_string is not “*”, fail parsing.</t>
                     <t>Discard the first character of input_string.</t>
                     <t>If there is not a “*” character before the end of input_string, fail parsing.</t>
                     <t>Let b64_content be the result of consuming content of input_string up to but not including the first instance of the character “*”.</t>
                     <t>Consume the “*” character at the beginning of input_string.</t>
                     <t>If b64_content contains a character not included in ALPHA, DIGIT, “+”, “/” and “=”, fail parsing.</t>
                     <t>Let binary_content be the result of Base 64 Decoding <xref target="RFC4648"/> b64_content, synthesizing padding if necessary (note the requirements about recipient behaviour below).</t>
                     <t>Return binary_content.</t>
                  </list>
               </t>
               <t>Because some implementations of base64 do not allow reject of encoded data that is not properly “=” padded (see <xref target="RFC4648" x:fmt="," x:sec="3.2"/>), parsers SHOULD NOT fail when it is not present, unless they cannot be configured to do so.</t>
               <t>Because some implementations of base64 do not allow rejection of encoded data that has non-zero pad bits (see <xref target="RFC4648" x:fmt="," x:sec="3.5"/>), parsers SHOULD NOT fail when it is present, unless they cannot be configured to do so.</t>
               <t>This specification does not relax the requirements in <xref target="RFC4648"/>, Section <xref target="RFC4648" x:fmt="number" x:sec="3.1"/> and <xref target="RFC4648" x:fmt="number" x:sec="3.3"/>; therefore, parsers MUST fail on characters outside the base64 alphabet, and on line feeds in encoded data.</t>
            </section>
            <section anchor="parse-boolean" title="Parsing a Boolean from Text">
               <t>Given an ASCII string as input_string, return a Boolean. input_string is modified to remove the parsed value.</t>
               <t>
                  <list style="numbers">
                     <t>If the first character of input_string is not “?”, fail parsing.</t>
                     <t>Discard the first character of input_string.</t>
                     <t>If the first character of input_string matches “1”, discard the first character, and return true.</t>
                     <t>If the first character of input_string matches “0”, discard the first character, and return false.</t>
                     <t>No value has matched; fail parsing.</t>
                  </list>
               </t>
            </section>
         </section>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <t>This draft has no actions for IANA.</t>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>The size of most types defined by Structured Headers is not limited; as a result, extremely large header fields could be an attack vector (e.g., for resource consumption). Most HTTP implementations limit the sizes of individual header fields as well as the overall header block size to mitigate such attacks.</t>
         <t>It is possible for parties with the ability to inject new HTTP header fields to change the meaning of a Structured Header. In some circumstances, this will cause parsing to fail, but it is not possible to reliably fail in all such circumstances.</t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="RFC7230">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7230"/>
            <seriesInfo name="DOI" value="10.17487/RFC7230"/>
         </reference>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </reference>
         <reference anchor="RFC5234">
            <front>
               <title>Augmented BNF for Syntax Specifications: ABNF</title>
               <author fullname="D. Crocker"
                       initials="D."
                       role="editor"
                       surname="Crocker"/>
               <author fullname="P. Overell" initials="P." surname="Overell"/>
               <date month="January" year="2008"/>
            </front>
            <seriesInfo name="STD" value="68"/>
            <seriesInfo name="RFC" value="5234"/>
            <seriesInfo name="DOI" value="10.17487/RFC5234"/>
         </reference>
         <reference anchor="RFC0020">
            <front>
               <title>ASCII format for network interchange</title>
               <author fullname="V.G. Cerf" initials="V.G." surname="Cerf"/>
               <date month="October" year="1969"/>
            </front>
            <seriesInfo name="STD" value="80"/>
            <seriesInfo name="RFC" value="20"/>
            <seriesInfo name="DOI" value="10.17487/RFC0020"/>
         </reference>
         <reference anchor="RFC4648">
            <front>
               <title>The Base16, Base32, and Base64 Data Encodings</title>
               <author fullname="S. Josefsson" initials="S." surname="Josefsson"/>
               <date month="October" year="2006"/>
            </front>
            <seriesInfo name="RFC" value="4648"/>
            <seriesInfo name="DOI" value="10.17487/RFC4648"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="IEEE754" target="http://ieeexplore.ieee.org/document/4610935/">
            <front>
               <title>IEEE Standard for Floating-Point Arithmetic</title>
               <author>
                  <organization>IEEE</organization>
               </author>
               <date month="August" year="2008"/>
            </front>
            <seriesInfo name="IEEE" value="754-2008"/>
            <seriesInfo name="DOI" value="10.1109/IEEESTD.2008.4610935"/>
            <seriesInfo name="ISBN" value="978-0-7381-5752-8"/>
            <annotation>See also <eref target="http://grouper.ieee.org/groups/754/">http://grouper.ieee.org/groups/754/</eref>.</annotation>
         </reference>
         <reference anchor="RFC7231">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7231"/>
            <seriesInfo name="DOI" value="10.17487/RFC7231"/>
         </reference>
         <reference anchor="RFC7540">
            <front>
               <title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
               <author fullname="M. Belshe" initials="M." surname="Belshe"/>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="M. Thomson"
                       initials="M."
                       role="editor"
                       surname="Thomson"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7540"/>
            <seriesInfo name="DOI" value="10.17487/RFC7540"/>
         </reference>
         <reference anchor="RFC7541">
            <front>
               <title>HPACK: Header Compression for HTTP/2</title>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="H. Ruellan" initials="H." surname="Ruellan"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7541"/>
            <seriesInfo name="DOI" value="10.17487/RFC7541"/>
         </reference>
         <reference anchor="RFC8259">
            <front>
               <title>The JavaScript Object Notation (JSON) Data Interchange Format</title>
               <author fullname="T. Bray" initials="T." role="editor" surname="Bray"/>
               <date month="December" year="2017"/>
            </front>
            <seriesInfo name="STD" value="90"/>
            <seriesInfo name="RFC" value="8259"/>
            <seriesInfo name="DOI" value="10.17487/RFC8259"/>
         </reference>
         <reference anchor="RFC7493">
            <front>
               <title>The I-JSON Message Format</title>
               <author fullname="T. Bray" initials="T." role="editor" surname="Bray"/>
               <date month="March" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7493"/>
            <seriesInfo name="DOI" value="10.17487/RFC7493"/>
         </reference>
      </references>
      <section anchor="acknowledgements" title="Acknowledgements">
         <t>Many thanks to Matthew Kerwin for his detailed feedback and careful consideration during the development of this specification.</t>
      </section>
      <section anchor="faq" title="Frequently Asked Questions">
         <section anchor="why-not-json" title="Why not JSON?">
            <t>Earlier proposals for structured headers were based upon JSON <xref target="RFC8259"/>. However, constraining its use to make it suitable for HTTP header fields required senders and recipients to implement specific additional handling.</t>
            <t>For example, JSON has specification issues around large numbers and objects with duplicate members. Although advice for avoiding these issues is available (e.g., <xref target="RFC7493"/>), it cannot be relied upon.</t>
            <t>Likewise, JSON strings are by default Unicode strings, which have a number of potential interoperability issues (e.g., in comparison). Although implementers can be advised to avoid non-ASCII content where unnecessary, this is difficult to enforce.</t>
            <t>Another example is JSON’s ability to nest content to arbitrary depths. Since the resulting memory commitment might be unsuitable (e.g., in embedded and other limited server deployments), it’s necessary to limit it in some fashion; however, existing JSON implementations have no such limits, and even if a limit is specified, it’s likely that some header field definition will find a need to violate it.</t>
            <t>Because of JSON’s broad adoption and implementation, it is difficult to impose such additional constraints across all implementations; some deployments would fail to enforce them, thereby harming interoperability. In short, if it looks like JSON, people will be tempted to use a JSON parser / serialiser on header fields.</t>
            <t>Since a major goal for Structured Headers is to improve interoperability and simplify implementation, these concerns led to a format that requires a dedicated parser and serializer.</t>
            <t>Additionally, there were widely shared feelings that JSON doesn’t “look right” in HTTP headers.</t>
         </section>
         <section anchor="structured-headers-dont-fit-my-data"
                  title="Structured Headers don’t “fit” my data.">
            <t>Structured headers intentionally limits the complexity of data structures, to assure that it can be processed in a performant manner with little overhead. This means that work is necessary to fit some data types into them.</t>
            <t>Sometimes, this can be achieved by creating limited substructures in values, and/or using more than one header. For example, consider:</t>
            <figure>
               <artwork type="example">
Example-Thing: name="Widget", cost=89.2, descriptions=(foo bar)
Example-Description: foo; url="https://example.net"; context=123,
                     bar; url="https://example.org"; context=456
</artwork>
            </figure>
            <t>Since the description contains an array of key/value pairs, we use a List to represent them, with the token for each item in the array used to identify it in the “descriptions” member of the Example-Thing header.</t>
            <t>When specifying more than one header, it’s important to remember to describe what a processor’s behaviour should be when one of the headers is missing.</t>
            <t>If you need to fit arbitrarily complex data into a header, Structured Headers is probably a poor fit for your use case.</t>
         </section>
      </section>
      <section anchor="implementation-notes" title="Implementation Notes">
         <t>A generic implementation of this specification should expose the top-level parse (<xref target="text-parse"/>) and serialize (<xref target="text-serialize"/>) functions. They need not be functions; for example, it could be implemented as an object, with methods for each of the different top-level types.</t>
         <t>For interoperability, it’s important that generic implementations be complete and follow the algorithms closely; see <xref target="strict"/>. To aid this, a common test suite is being maintained by the community at <eref target="https://github.com/httpwg/structured-header-tests">https://github.com/httpwg/structured-header-tests</eref>.</t>
         <t>Implementers should note that dictionaries and parameters are order-preserving maps. Some headers may not convey meaning in the ordering of these data types, but it should still be exposed so that applications which need to use it will have it available.</t>
         <t>Likewise, implementations should note that it’s important to preserve the distinction between tokens and strings. While most programming languages have native types that map to the other types well, it may be necessary to create a wrapper “token” object or use a parameter on functions to assure that these types remain separate.</t>
      </section>
      <section anchor="changes" title="Changes">
         <t>
            <spanx>RFC Editor: Please remove this section before publication.</spanx>
         </t>
         <section anchor="since-draft-ietf-httpbis-header-structure-12"
                  title="Since draft-ietf-httpbis-header-structure-12">
            <t>
               <list style="symbols">
                  <t>Editorial improvements.</t>
                  <t>Reworked float serialisation (#896).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-11"
                  title="Since draft-ietf-httpbis-header-structure-11">
            <t>
               <list style="symbols">
                  <t>Allow * in key (#844).</t>
                  <t>Constrain floats to six digits of precision (#848).</t>
                  <t>Allow dictionary members to have parameters (#842).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-10"
                  title="Since draft-ietf-httpbis-header-structure-10">
            <t>
               <list style="symbols">
                  <t>Update abstract (#799).</t>
                  <t>Input and output are now arrays of bytes (#662).</t>
                  <t>Implementations need to preserve difference between token and string (#790).</t>
                  <t>Allow empty dictionaries and lists (#781).</t>
                  <t>Change parameterized lists to have primary items (#797).</t>
                  <t>Allow inner lists in both dictionaries and lists; removes lists of lists (#816).</t>
                  <t>Subsume Parameterised Lists into Lists (#839).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-09"
                  title="Since draft-ietf-httpbis-header-structure-09">
            <t>
               <list style="symbols">
                  <t>Changed Boolean from T/F to 1/0 (#784).</t>
                  <t>Parameters are now ordered maps (#765).</t>
                  <t>Clamp integers to 15 digits (#737).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-08"
                  title="Since draft-ietf-httpbis-header-structure-08">
            <t>
               <list style="symbols">
                  <t>Disallow whitespace before items properly (#703).</t>
                  <t>Created “key” for use in dictionaries and parameters, rather than relying on identifier (#702). Identifiers have a separate minimum supported size.</t>
                  <t>Expanded the range of special characters allowed in identifier to include all of ALPHA, “.”, “:”, and “%” (#702).</t>
                  <t>Use “?” instead of “!” to indicate a Boolean (#719).</t>
                  <t>Added “Intentionally Strict Processing” (#684).</t>
                  <t>Gave better names for referring specs to use in Parameterised Lists (#720).</t>
                  <t>Added Lists of Lists (#721).</t>
                  <t>Rename Identifier to Token (#725).</t>
                  <t>Add implementation guidance (#727).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-07"
                  title="Since draft-ietf-httpbis-header-structure-07">
            <t>
               <list style="symbols">
                  <t>Make Dictionaries ordered mappings (#659).</t>
                  <t>Changed “binary content” to “byte sequence” to align with Infra specification (#671).</t>
                  <t>Changed “mapping” to “map” for #671.</t>
                  <t>Don’t fail if byte sequences aren’t “=” padded (#658).</t>
                  <t>Add Booleans (#683).</t>
                  <t>Allow identifiers in items again (#629).</t>
                  <t>Disallowed whitespace before items (#703).</t>
                  <t>Explain the consequences of splitting a string across multiple headers (#686).</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-06"
                  title="Since draft-ietf-httpbis-header-structure-06">
            <t>
               <list style="symbols">
                  <t>Add a FAQ.</t>
                  <t>Allow non-zero pad bits.</t>
                  <t>Explicitly check for integers that violate constraints.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-05"
                  title="Since draft-ietf-httpbis-header-structure-05">
            <t>
               <list style="symbols">
                  <t>Reorganise specification to separate parsing out.</t>
                  <t>Allow referencing specs to use ABNF.</t>
                  <t>Define serialisation algorithms.</t>
                  <t>Refine relationship between ABNF, parsing and serialisation algorithms.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-04"
                  title="Since draft-ietf-httpbis-header-structure-04">
            <t>
               <list style="symbols">
                  <t>Remove identifiers from item.</t>
                  <t>Remove most limits on sizes.</t>
                  <t>Refine number parsing.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-03"
                  title="Since draft-ietf-httpbis-header-structure-03">
            <t>
               <list style="symbols">
                  <t>Strengthen language around failure handling.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-02"
                  title="Since draft-ietf-httpbis-header-structure-02">
            <t>
               <list style="symbols">
                  <t>Split Numbers into Integers and Floats.</t>
                  <t>Define number parsing.</t>
                  <t>Tighten up binary parsing and give it an explicit end delimiter.</t>
                  <t>Clarify that mappings are unordered.</t>
                  <t>Allow zero-length strings.</t>
                  <t>Improve string parsing algorithm.</t>
                  <t>Improve limits in algorithms.</t>
                  <t>Require parsers to combine header fields before processing.</t>
                  <t>Throw an error on trailing garbage.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-01"
                  title="Since draft-ietf-httpbis-header-structure-01">
            <t>
               <list style="symbols">
                  <t>Replaced with draft-nottingham-structured-headers.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-header-structure-00"
                  title="Since draft-ietf-httpbis-header-structure-00">
            <t>
               <list style="symbols">
                  <t>Added signed 64bit integer type.</t>
                  <t>Drop UTF8, and settle on BCP137 ::EmbeddedUnicodeChar for h1-unicode-string.</t>
                  <t>Change h1_blob delimiter to “:” since “’” is valid t_char</t>
               </list>
            </t>
         </section>
      </section>
   </back>
</rfc>
