<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.7.29 (Ruby 3.2.2) -->
<?rfc tocindent="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     consensus="true"
     docName="draft-ietf-httpbis-retrofit-latest"
     ipr="trust200902"
     sortRefs="true"
     symRefs="true"
     tocInclude="true">
   <x:feedback template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title abbrev="Retrofit Structured Fields">Retrofit Structured Fields for HTTP</title>
      <author fullname="Mark Nottingham" initials="M." surname="Nottingham">
         <address>
            <postal>
               <postalLine>Prahran</postalLine>
               <postalLine>Australia</postalLine>
            </postal>
            <email>mnot@mnot.net</email>
            <uri>https://www.mnot.net/</uri>
         </address>
      </author>
      <date/>
      <area>Web and Internet Transport</area>
      <workgroup>HTTP</workgroup>
      <keyword>structured fields</keyword>
      <keyword>http</keyword>
      <abstract><?line 49?>
         <t>This specification nominates a selection of existing HTTP fields whose values are compatible with Structured Fields syntax, so that they can be handled as such (subject to certain caveats).</t>
         <t>To accommodate some additional fields whose syntax is not compatible, it also defines mappings of their semantics into Structured Fields. It does not specify how to convey them in HTTP messages.</t>
      </abstract>
      <note removeInRFC="true" title="About This Document">
         <t>Status information for this document may be found at <eref target="https://datatracker.ietf.org/doc/draft-ietf-httpbis-retrofit/"/>.</t>
         <t>Discussion of this document takes place on the HTTP Working Group mailing list (<eref target="mailto:ietf-http-wg@w3.org"/>), which is archived at <eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/"/>. Working Group information can be found at <eref target="https://httpwg.org/"/>.</t>
         <t>Source for this draft and an issue tracker can be found at <eref target="https://github.com/httpwg/http-extensions/labels/retrofit"/>.</t>
      </note>
   </front>
   <middle><?line 55?>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>Structured Field Values for HTTP <xref target="STRUCTURED-FIELDS"/> introduced a data model with associated parsing and serialization algorithms for use by new HTTP field values. Fields that are defined as Structured Fields can bring advantages that include:</t>
         <t>
            <list style="symbols">
               <t>Improved interoperability and security: precisely defined parsing and serialisation algorithms are typically not available for fields defined with just ABNF and/or prose.</t>
               <t>Reuse of common implementations: many parsers for other fields are specific to a single field or a small family of fields.</t>
               <t>Canonical form: because a deterministic serialisation algorithm is defined for each type, Structure Fields have a canonical representation.</t>
               <t>Enhanced API support: a regular data model makes it easier to expose field values as a native data structure in implementations.</t>
               <t>Alternative serialisations: While <xref target="STRUCTURED-FIELDS"/> defines a textual serialisation of that data model, other, more efficient serialisations of the underlying data model are also possible.</t>
            </list>
         </t>
         <t>However, a field needs to be defined as a Structured Field for these benefits to be realised. Many existing fields are not, making up the bulk of header and trailer fields seen in HTTP traffic on the internet.</t>
         <t>This specification defines how a selection of existing HTTP fields can be handled as Structured Fields, so that these benefits can be realised -- thereby making them Retrofit Structured Fields.</t>
         <t>It does so using two techniques. <xref target="compatible"/> lists compatible fields -- those that can be handled as if they were Structured Fields due to the similarity of their defined syntax to that in Structured Fields. <xref target="mapped"/> lists mapped fields -- those whose syntax needs to be transformed into an underlying data model which is then mapped into that defined by Structured Fields.</t>
         <section anchor="using-retrofit-structured-fields">
            <name>Using Retrofit Structured Fields</name>
            <t>Retrofitting data structures onto existing and widely-deployed HTTP fields requires careful handling to assure interoperability and security. This section highlights considerations for applications that use Retrofit Structured Fields.</t>
            <t>While the majority of field values seen in HTTP traffic should be able to be parsed or mapped successfully, some will not. An application using Retrofit Structured Fields will need to define how unsuccessful values will be handled.</t>
            <t>For example, an API that exposes field values using Structured Fields data types might make the field value available as a string in cases where the field did not successfully parse or map.</t>
            <t>The mapped field values described in <xref target="mapped"/> are not compatible with the original syntax of their fields, and so cannot be used unless parties processing them have explicitly indicated their support for that form of the field value. An application using Retrofit Structured Fields will need to define how to negotiate support for them.</t>
            <t>For example, an alternative serialization of fields that takes advantage of Structured Fields would need to establish an explicit negotiation mechanism to assure that both peers would handle that serialization appropriately before using it.</t>
            <t>See also the security considerations in <xref target="security"/>.</t>
         </section>
         <section anchor="notational-conventions">
            <name>Notational Conventions</name>
            <t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" 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>
            <?line -18?>
         </section>
      </section>
      <section anchor="compatible">
         <name>Compatible Fields</name>
         <t>The HTTP fields listed in <xref target="compatible-fields"/> have values that can be handled as Structured Field Values according to the parsing and serialisation algorithms in <xref target="STRUCTURED-FIELDS"/> corresponding to the listed top-level type, subject to the caveats in <xref target="compatible-caveats"/>.</t>
         <t>The top-level types are chosen for compatibility with the defined syntax of the field as well as with actual internet traffic. However, not all instances of these fields will successfully parse as a Structured Field Value. This might be because the field value is clearly invalid, or it might be because it is valid but not parseable as a Structured Field.</t>
         <t>An application using this specification will need to consider how to handle such field values. Depending on its requirements, it might be advisable to reject such values, treat them as opaque strings, or attempt to recover a Structured Field Value from them in an ad hoc fashion.</t>
         <texttable anchor="compatible-fields" title="Compatible Fields">
            <ttcol align="left">Field Name</ttcol>
            <ttcol align="left">Structured Type</ttcol>
            <c>Accept</c>
            <c>List</c>
            <c>Accept-Encoding</c>
            <c>List</c>
            <c>Accept-Language</c>
            <c>List</c>
            <c>Accept-Patch</c>
            <c>List</c>
            <c>Accept-Post</c>
            <c>List</c>
            <c>Accept-Ranges</c>
            <c>List</c>
            <c>Access-Control-Allow-Credentials</c>
            <c>Item</c>
            <c>Access-Control-Allow-Headers</c>
            <c>List</c>
            <c>Access-Control-Allow-Methods</c>
            <c>List</c>
            <c>Access-Control-Allow-Origin</c>
            <c>Item</c>
            <c>Access-Control-Expose-Headers</c>
            <c>List</c>
            <c>Access-Control-Max-Age</c>
            <c>Item</c>
            <c>Access-Control-Request-Headers</c>
            <c>List</c>
            <c>Access-Control-Request-Method</c>
            <c>Item</c>
            <c>Age</c>
            <c>Item</c>
            <c>Allow</c>
            <c>List</c>
            <c>ALPN</c>
            <c>List</c>
            <c>Alt-Svc</c>
            <c>Dictionary</c>
            <c>Alt-Used</c>
            <c>Item</c>
            <c>Cache-Control</c>
            <c>Dictionary</c>
            <c>CDN-Loop</c>
            <c>List</c>
            <c>Clear-Site-Data</c>
            <c>List</c>
            <c>Connection</c>
            <c>List</c>
            <c>Content-Encoding</c>
            <c>List</c>
            <c>Content-Language</c>
            <c>List</c>
            <c>Content-Length</c>
            <c>List</c>
            <c>Content-Type</c>
            <c>Item</c>
            <c>Cross-Origin-Resource-Policy</c>
            <c>Item</c>
            <c>DNT</c>
            <c>Item</c>
            <c>Expect</c>
            <c>Dictionary</c>
            <c>Expect-CT</c>
            <c>Dictionary</c>
            <c>Host</c>
            <c>Item</c>
            <c>Keep-Alive</c>
            <c>Dictionary</c>
            <c>Max-Forwards</c>
            <c>Item</c>
            <c>Origin</c>
            <c>Item</c>
            <c>Pragma</c>
            <c>Dictionary</c>
            <c>Prefer</c>
            <c>Dictionary</c>
            <c>Preference-Applied</c>
            <c>Dictionary</c>
            <c>Retry-After</c>
            <c>Item</c>
            <c>Sec-WebSocket-Extensions</c>
            <c>List</c>
            <c>Sec-WebSocket-Protocol</c>
            <c>List</c>
            <c>Sec-WebSocket-Version</c>
            <c>Item</c>
            <c>Server-Timing</c>
            <c>List</c>
            <c>Surrogate-Control</c>
            <c>Dictionary</c>
            <c>TE</c>
            <c>List</c>
            <c>Timing-Allow-Origin</c>
            <c>List</c>
            <c>Trailer</c>
            <c>List</c>
            <c>Transfer-Encoding</c>
            <c>List</c>
            <c>Upgrade-Insecure-Requests</c>
            <c>Item</c>
            <c>Vary</c>
            <c>List</c>
            <c>X-Content-Type-Options</c>
            <c>Item</c>
            <c>X-Frame-Options</c>
            <c>Item</c>
            <c>X-XSS-Protection</c>
            <c>List</c>
         </texttable>
         <section anchor="compatible-caveats">
            <name>Caveats</name>
            <t>Note the following caveats regarding compatibility:</t>
            <dl>
               <dt>Parsing differences:</dt>
               <dd>
                  <t>Some values may fail to parse as Structured Fields, even though they are valid according to their originally specified syntax. For example, HTTP parameter names are case-insensitive (per <xref section="5.6.6"
                           sectionFormat="of"
                           target="HTTP"
                           x:title="Parameters"><?aug-anchor parameter?></xref>), but Structured Fields require them to be all-lowercase. Likewise, many Dictionary-based fields (e.g., Cache-Control, Expect-CT, Pragma, Prefer, Preference-Applied, Surrogate-Control) have case-insensitive keys. Similarly, the parameters rule in HTTP (see <xref section="5.6.6"
                           sectionFormat="of"
                           target="HTTP"
                           x:title="Parameters"><?aug-anchor parameter?></xref>) allows whitespace before the ";" delimiter, but Structured Fields does not. And, <xref section="5.6.4"
                           sectionFormat="of"
                           target="HTTP"
                           x:title="Quoted Strings"><?aug-anchor quoted.strings?></xref> allows backslash-escaping most characters in quoted strings, whereas Structured Field Strings only escape "\" and DQUOTE. The vast majority of fields seen in typical traffic do not exhibit these behaviors.</t>
               </dd>
               <dt>Error handling:</dt>
               <dd>
                  <t>Parsing algorithms specified (or just widely implemented) for current HTTP headers may differ from those in Structured Fields in details such as error handling. For example, HTTP specifies that repeated directives in the Cache-Control header field have a different precedence than that assigned by a Dictionary structured field (which Cache-Control is mapped to).</t>
               </dd>
               <dt>Token limitations:</dt>
               <dd>
                  <t>In Structured Fields, tokens are required to begin with an alphabetic character or "*", whereas HTTP tokens allow a wider range of characters. This prevents use of mapped values that begin with one of these characters. For example, media types, field names, methods, range-units, character and transfer codings that begin with a number or special character other than "*" might be valid HTTP protocol elements, but will not be able to be represented as Structured Field Tokens.</t>
               </dd>
               <dt>Integer limitations:</dt>
               <dd>
                  <t>Structured Fields Integers can have at most 15 digits; larger values will not be able to be represented in them.</t>
               </dd>
               <dt>IPv6 Literals:</dt>
               <dd>
                  <t>Fields whose values contain IPv6 literal addresses (such as CDN-Loop, Host, and Origin) are not able to be represented as Structured Fields Tokens, because the brackets used to delimit them are not allowed in Tokens.</t>
               </dd>
               <dt>Empty Field Values:</dt>
               <dd>
                  <t>Empty and whitespace-only field values are considered errors in Structured Fields. For compatible fields, an empty field indicates that the field should be silently ignored.</t>
               </dd>
               <dt>Alt-Svc:</dt>
               <dd>
                  <t>Some ALPN tokens (e.g., <spanx style="verb">h3-Q43</spanx>) do not conform to key's syntax, and therefore cannot be represented as a Token. Since the final version of HTTP/3 uses the <spanx style="verb">h3</spanx> token, this shouldn't be a long-term issue, although future tokens may again violate this assumption.</t>
               </dd>
               <dt>Content-Length:</dt>
               <dd>
                  <t>Note that Content-Length is defined as a List because it is not uncommon for implementations to mistakenly send multiple values. See <xref section="8.6"
                           sectionFormat="of"
                           target="HTTP"
                           x:title="Content-Length"><?aug-anchor field.content-length?></xref> for handling requirements.</t>
               </dd>
               <dt>Retry-After:</dt>
               <dd>
                  <t>Only the delta-seconds form of Retry-After can be represented; a Retry-After value containing a http-date will need to be converted into delta-seconds to be conveyed as a Structured Field Value.</t>
               </dd>
            </dl>
         </section>
      </section>
      <section anchor="mapped">
         <name>Mapped Fields</name>
         <t>Some HTTP field values have syntax that cannot be successfully parsed as Structured Field values. Instead, it is necessary to map them into a Structured Field value.</t>
         <t>For example, the Date HTTP header field carries a date:</t>
         <figure>
            <sourcecode type="http-message">
Date: Sun, 06 Nov 1994 08:49:37 GMT
</sourcecode>
         </figure>
         <t>Its value would be mapped to:</t>
         <figure>
            <sourcecode type="http-message-new">
@784111777
</sourcecode>
         </figure>
         <t>Unlike those listed in <xref target="compatible"/>, these representations are not compatible with the original fields' syntax, and <bcp14>MUST NOT</bcp14> be used unless they are explicitly and unambiguously supported. For example, this means that sending them to a next-hop recipient in HTTP requires prior negotiation. This specification does not define how to do so.</t>
         <section anchor="urls">
            <name>URLs</name>
            <t>The field names in <xref target="url-fields"/> have values that can be mapped into Structured Field values by treating the original field's value as a String.</t>
            <texttable anchor="url-fields" title="URL Fields">
               <ttcol align="left">Field Name</ttcol>
               <c>Content-Location</c>
               <c>Location</c>
               <c>Referer</c>
            </texttable>
            <t>For example, this Location field:</t>
            <figure>
               <sourcecode type="http-message">
Location: https://example.com/foo
</sourcecode>
            </figure>
            <t>would have a mapped value of:</t>
            <figure>
               <artwork>
"https://example.com/foo"
</artwork>
            </figure>
         </section>
         <section anchor="dates">
            <name>Dates</name>
            <t>The field names in <xref target="date-fields"/> have values that can be mapped into Structured Field values by parsing their payload according to <xref section="5.6.7"
                     sectionFormat="of"
                     target="HTTP"
                     x:title="Date/Time Formats"><?aug-anchor http.date?></xref> and representing the result as a Date.</t>
            <texttable anchor="date-fields" title="Date Fields">
               <ttcol align="left">Field Name</ttcol>
               <c>Date</c>
               <c>Expires</c>
               <c>If-Modified-Since</c>
               <c>If-Unmodified-Since</c>
               <c>Last-Modified</c>
            </texttable>
            <t>For example, an Expires field's value could be mapped as:</t>
            <figure>
               <sourcecode type="http-message-new">
@1659578233
</sourcecode>
            </figure>
         </section>
         <section anchor="etags">
            <name>ETags</name>
            <t>The field value of the ETag header field can be mapped into a Structured Field value by representing the entity-tag as a String, and the weakness flag as a Boolean "w" parameter on it, where true indicates that the entity-tag is weak; if 0 or unset, the entity-tag is strong.</t>
            <t>For example, this ETag header field:</t>
            <figure>
               <sourcecode type="http-message">
ETag: W/"abcdef"
</sourcecode>
            </figure>
            <t>would have a mapped value of:</t>
            <figure>
               <artwork>
"abcdef"; w
</artwork>
            </figure>
            <t>If-None-Match's field value can be mapped into a Structured Field value which is a List of the structure described above. When a field value contains "*", it is represented as a Token.</t>
            <t>Likewise, If-Match's field value can be mapped into a Structured Field value in the same manner.</t>
            <t>For example, this If-None-Match field:</t>
            <figure>
               <sourcecode type="http-message">
If-None-Match: W/"abcdef", "ghijkl", *
</sourcecode>
            </figure>
            <t>would have a mapped value of:</t>
            <figure>
               <artwork>
"abcdef"; w, "ghijkl", *
</artwork>
            </figure>
         </section>
         <section anchor="cookies">
            <name>Cookies</name>
            <t>The field values of the Cookie and Set-Cookie fields <xref target="COOKIES"/> can be mapped into Structured Fields Lists.</t>
            <t>In each case, a cookie is represented as an Inner List containing two Items; the cookie name and value. The cookie name is always a String; the cookie value is a String, unless it can be successfully parsed as the textual representation of another, bare Item structured type (e.g., Byte Sequence, Decimal, Integer, Token, or Boolean).</t>
            <t>Cookie attributes map to Parameters on the Inner List, with the parameter name being forced to lowercase. Cookie attribute values are Strings unless a specific type is defined for them. This specification defines types for existing cookie attributes in <xref target="cookie-params"/>.</t>
            <texttable anchor="cookie-params" title="Set-Cookie Parameter Types">
               <ttcol align="left">Parameter Name</ttcol>
               <ttcol align="left">Structured Type</ttcol>
               <c>Domain</c>
               <c>String</c>
               <c>HttpOnly</c>
               <c>Boolean</c>
               <c>Expires</c>
               <c>Date</c>
               <c>Max-Age</c>
               <c>Integer</c>
               <c>Path</c>
               <c>String</c>
               <c>Secure</c>
               <c>Boolean</c>
               <c>SameSite</c>
               <c>Token</c>
            </texttable>
            <t>The Expires attribute is mapped to a Date representation of parsed-cookie-date (see <xref section="5.1.1" sectionFormat="of" target="COOKIES"/>).</t>
            <t>For example, this Set-Cookie field:</t>
            <figure>
               <sourcecode type="http-message">
Set-Cookie: Lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT;
               samesite=Strict; secure
</sourcecode>
            </figure>
            <t>would have a mapped value of:</t>
            <figure>
               <sourcecode type="http-message-new">
("Lang" "en-US"); expires=@1623233894;
               samesite=Strict; secure
</sourcecode>
            </figure>
            <t>And this Cookie field:</t>
            <figure>
               <sourcecode type="http-message">
Cookie: SID=31d4d96e407aad42; lang=en-US
</sourcecode>
            </figure>
            <t>would have a mapped value of:</t>
            <figure>
               <sourcecode type="http-message-new">
("SID" "31d4d96e407aad42"), ("lang" "en-US")
</sourcecode>
            </figure>
         </section>
      </section>
      <section anchor="iana-considerations">
         <name>IANA Considerations</name>
         <t>Please add the following note to the "Hypertext Transfer Protocol (HTTP) Field Name Registry":</t>
         <ul empty="true">
            <li>
               <t>A prefix of "*" in the Structured Type column indicates that it is a retrofit type (i.e., not natively Structured); see RFC nnnn.</t>
            </li>
         </ul>
         <t>Then, add a new column, "Structured Type", with the values from <xref target="compatible"/> assigned to the nominated registrations, prefixing each with "*" to indicate that it is a retrofit type.</t>
         <t>Finally, add a new column to the "Cookie Attribute Registry" established by <xref target="COOKIES"/> with the title "Structured Type", using information from <xref target="cookie-params"/>.</t>
      </section>
      <section anchor="security">
         <name>Security Considerations</name>
         <t>
            <xref target="compatible"/> identifies existing HTTP fields that can be parsed and serialised with the algorithms defined in <xref target="STRUCTURED-FIELDS"/>. Variances from existing parser behavior might be exploitable, particularly if they allow an attacker to target one implementation in a chain (e.g., an intermediary). However, given the considerable variance in parsers already deployed, convergence towards a single parsing algorithm is likely to have a net security benefit in the longer term.</t>
         <t>
            <xref target="mapped"/> defines alternative representations of existing fields. Because downstream consumers might interpret the message differently based upon whether they recognise the alternative representation, implementations are prohibited from generating such values unless they have negotiated support for them with their peer. This specification does not define such a mechanism, but any such definition needs to consider the implications of doing so carefully.</t>
      </section>
   </middle>
   <back>
      <references anchor="sec-normative-references" title="Normative References">
         <reference anchor="HTTP">
            <front>
               <title>HTTP Semantics</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="M. Nottingham"
                       initials="M."
                       role="editor"
                       surname="Nottingham"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2022"/>
            </front>
            <seriesInfo name="STD" value="97"/>
            <seriesInfo name="RFC" value="9110"/>
            <seriesInfo name="DOI" value="10.17487/RFC9110"/>
            <x:source basename="rfc9110" href="rfc9110.xml"/>
         </reference>
         <reference anchor="STRUCTURED-FIELDS">
            <front>
               <title>Structured Field Values for HTTP</title>
               <author fullname="Mark Nottingham" initials="M." surname="Nottingham">
                  <organization>Cloudflare</organization>
               </author>
               <author fullname="Poul-Henning Kamp" initials="P." surname="Kamp">
                  <organization>The Varnish Cache Project</organization>
               </author>
               <date day="21" month="April" year="2024"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-sfbis-06"/>
         </reference>
         <reference anchor="COOKIES">
            <front>
               <title>Cookies: HTTP State Management Mechanism</title>
               <author fullname="Steven Bingler" initials="S." surname="Bingler"/>
               <author fullname="Mike West" initials="M." surname="West">
                  <organization>Google LLC</organization>
               </author>
               <author fullname="John Wilander" initials="J." surname="Wilander">
                  <organization>Apple, Inc</organization>
               </author>
               <date day="1" month="December" year="2025"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-rfc6265bis-22"/>
         </reference>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </reference>
      </references>
      <?line 376?>
   </back>
</rfc>
