<?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.5.26 (Ruby 2.6.4) -->
<?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-00"
     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 year="2021" month="February" day="26"/>
      <keyword>structured fields</keyword>
      <keyword>http</keyword>
      <abstract>
         <t>This specification defines how a selection of existing HTTP fields can be handled as Structured Fields.</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>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>Structured Field Values for HTTP <xref target="STRUCTURED-FIELDS"/> introduced a data model with associated parsing and serialisation algorithms for use by new HTTP field values. Header fields that are defined as Structured Fields can realise a number of benefits, including:</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>
         <t>While implementations can parse and serialise Compatible Fields as Structured Fields subject to the caveats in <xref target="compatible"/>, a sender cannot generate mapped fields from <xref target="mapped"/> and expect them to be understood and acted upon by the recipient without prior negotiation. This specification does not define such a mechanism.</t>
         <section anchor="notational-conventions">
            <name>Notational Conventions</name>
            <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>
         </section>
      </section>
      <section anchor="compatible">
         <name>Compatible Fields</name>
         <t>HTTP fields with the following names can usually have their values handled as Structured Fields according to the listed parsing and serialisation algorithms in <xref target="STRUCTURED-FIELDS"/>, subject to the listed caveats.</t>
         <t>The listed types are chosen for compatibility with the defined syntax of the field as well as with actual Internet traffic (see <xref target="numbers"/>). However, not all instances of these fields will successfully parse. 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 value from them in an ad hoc fashion.</t>
         <t>
            <list style="symbols">
               <t>Accept - List</t>
               <t>Accept-Encoding - List</t>
               <t>Accept-Language - List</t>
               <t>Accept-Patch - List</t>
               <t>Accept-Ranges - List</t>
               <t>Access-Control-Allow-Credentials - Item</t>
               <t>Access-Control-Allow-Headers - List</t>
               <t>Access-Control-Allow-Methods - List</t>
               <t>Access-Control-Allow-Origin - Item</t>
               <t>Access-Control-Expose-Headers - List</t>
               <t>Access-Control-Max-Age - Item</t>
               <t>Access-Control-Request-Headers - List</t>
               <t>Access-Control-Request-Method - Item</t>
               <t>Age - Item</t>
               <t>Allow - List</t>
               <t>ALPN - List</t>
               <t>Alt-Svc - Dictionary</t>
               <t>Alt-Used - Item</t>
               <t>Cache-Control - Dictionary</t>
               <t>Connection - List</t>
               <t>Content-Encoding - List</t>
               <t>Content-Language - List</t>
               <t>Content-Length - List</t>
               <t>Content-Type - Item</t>
               <t>Cross-Origin-Resource-Policy - Item</t>
               <t>Expect - Item</t>
               <t>Expect-CT - Dictionary</t>
               <t>Host - Item</t>
               <t>Keep-Alive - Dictionary</t>
               <t>Origin - Item</t>
               <t>Pragma - Dictionary</t>
               <t>Prefer - Dictionary</t>
               <t>Preference-Applied - Dictionary</t>
               <t>Retry-After - Item</t>
               <t>Surrogate-Control - Dictionary</t>
               <t>TE - List</t>
               <t>Timing-Allow-Origin: List</t>
               <t>Trailer - List</t>
               <t>Transfer-Encoding - List</t>
               <t>Vary - List</t>
               <t>X-Content-Type-Options - Item</t>
               <t>X-Frame-Options - Item</t>
               <t>X-XSS-Protection - List</t>
            </list>
         </t>
         <t>Note the following caveats:</t>
         <dl>
            <dt>Parameter names:</dt>
            <dd>
               <t>HTTP parameter names are case-insensitive (as per <xref section="5.6.6" sectionFormat="of" target="HTTP"><?aug-anchor parameter?><?aug-title Parameters?></xref>), but Structured Fields require them to be all-lowercase. Although the vast majority of parameters seen in typical traffic are all-lowercase, compatibility can be improved by force-lowercasing parameters when encountered.</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. 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>Cache-Control, Expect-CT, Pragma, Prefer, Preference-Applied, Surrogate-Control:</dt>
            <dd>
               <t>These Dictionary-based fields consider the key to be case-insensitive, but Structured Fields requires keys to be all-lowercase. Although the vast majority of values seen in typical traffic are all-lowercase, compatibility can be improved by force-lowercasing these Dictionary keys when encountered.</t>
            </dd>
            <dt>Content-Length:</dt>
            <dd>
               <t>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"><?aug-anchor field.content-length?><?aug-title Content-Length?></xref> for handling requirements.</t>
            </dd>
            <dt>Retry-After:</dt>
            <dd>
               <t>Only the delta-seconds form of Retry-After is supported; a Retry-After value containing a http-date will need to be either converted into delta-seconds or represented as a raw value.</t>
            </dd>
         </dl>
      </section>
      <section anchor="mapped">
         <name>Mapped Fields</name>
         <t>Some HTTP fields can have their values represented in Structured Fields by mapping them into its data types and then serialising the result using an alternative field name.</t>
         <t>For example, the Date HTTP header field carries a string representing a date:</t>
         <figure>
            <sourcecode type="http-message">
Date: Sun, 06 Nov 1994 08:49:37 GMT
</sourcecode>
         </figure>
         <t>Its value is more efficiently represented as an integer number of delta seconds from the Unix epoch (00:00:00 UTC on 1 January 1970, minus leap seconds). Thus, the example above would be mapped as:</t>
         <figure>
            <sourcecode type="http-message">
SF-Date: 784072177
</sourcecode>
         </figure>
         <t>As in <xref target="compatible"/>, these fields are unable to represent values that are not parseable, and so an application using this specification will need to how to support such values. Typically, handling them using the original field name is sufficient.</t>
         <t>Each field name listed below indicates a replacement field name and a means of mapping its original value into a Structured Field.</t>
         <section anchor="urls">
            <name>URLs</name>
            <t>The following field names (paired with their replacement field names) have values that can be represented as Structured Fields by considering the original field's value as a string.</t>
            <t>
               <list style="symbols">
                  <t>Content-Location - SF-Content-Location</t>
                  <t>Location - SF-Location</t>
                  <t>Referer - SF-Referer</t>
               </list>
            </t>
            <t>For example, a Location field could be represented as:</t>
            <figure>
               <sourcecode type="http-message">
SF-Location: "https://example.com/foo"
</sourcecode>
            </figure>
         </section>
         <section anchor="dates">
            <name>Dates</name>
            <t>The following field names (paired with their replacement field names) have values that can be represented as Structured Fields by parsing their payload according to <xref section="5.6.7" sectionFormat="of" target="HTTP"><?aug-anchor http.date?><?aug-title Date/Time Formats?></xref> and representing the result as an integer number of seconds delta from the Unix Epoch (00:00:00 UTC on 1 January 1970, minus leap seconds).</t>
            <t>
               <list style="symbols">
                  <t>Date - SF-Date</t>
                  <t>Expires - SF-Expires</t>
                  <t>If-Modified-Since - SF-IMS</t>
                  <t>If-Unmodified-Since - SF-IUS</t>
                  <t>Last-Modified - SF-LM</t>
               </list>
            </t>
            <t>For example, an Expires field could be represented as:</t>
            <figure>
               <sourcecode type="http-message">
SF-Expires: 1571965240
</sourcecode>
            </figure>
         </section>
         <section anchor="etags">
            <name>ETags</name>
            <t>The field value of the ETag header field can be represented as a String Structured Field 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:</t>
            <figure>
               <sourcecode type="http-message">
SF-ETag: "abcdef"; w=?1
</sourcecode>
            </figure>
            <t>If-None-Match's field value can be represented as SF-INM, which is a List of the structure described above.</t>
            <t>For example:</t>
            <figure>
               <sourcecode type="http-message">
SF-INM: "abcdef"; w=?1, "ghijkl"
</sourcecode>
            </figure>
         </section>
         <section anchor="links">
            <name>Links</name>
            <t>The field value of the Link header field <xref target="RFC8288"/> can be represented in the SF-Link List Structured Field by representing the URI-Reference as a string, and link-param as parameters.</t>
            <t>For example:</t>
            <figure>
               <sourcecode type="http-message">
SF-Link: "/terms"; rel="copyright"; anchor="#foo"
</sourcecode>
            </figure>
         </section>
         <section anchor="cookies">
            <name>Cookies</name>
            <t>The field values of the Cookie and Set-Cookie fields <xref target="RFC6265"/> can be represented in the SF-Cookie Structured Field (a List) and SF-Set-Cookie Structured Field (a Dictionary), respectively.</t>
            <t>In each case, cookie names are serialized as tokens, whereas their values are serialised as Strings, unless they can be represented accurately and unambiguously using the textual representation of another structured types (e.g., an Integer or Decimal).</t>
            <t>Set-Cookie parameters map to parameters on the appropriate SF-Set-Cookie member, with the parameter name being forced to lowercase. Set-Cookie parameter values are Strings unless a specific type is defined. This specification defines the following parameter types:</t>
            <t>
               <list style="symbols">
                  <t>Max-Age: Integer</t>
                  <t>Secure: Boolean</t>
                  <t>HttpOnly: Boolean</t>
                  <t>SameSite: Token</t>
               </list>
            </t>
            <t>Note that cookies in both fields are separated by commas, not semicolons, and multiple cookies can appear in each field.</t>
            <t>For example:</t>
            <figure>
               <sourcecode type="http-message">
SF-Set-Cookie: lang=en-US; expires="Wed, 09 Jun 2021 10:18:14 GMT";
               samesite=Strict
SF-Cookie: 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 HTTP Field Name Registry:</t>
         <ul empty="true">
            <li>
               <t>The "Structured Type" column indicates the type of the field as per RFC8941, if any, and may be "Dictionary", "List" or "Item". A prefix of "*" indicates that it is a retrofit type (i.e., not natively Structured); see [this specification].</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>Then, add the following field names into the HTTP Field Name Registry, with the corresponding Structured Type as indicated, a status of "permanent" and referring to this document:</t>
         <t>
            <list style="symbols">
               <t>SF-Content-Location - String</t>
               <t>SF-Location - String</t>
               <t>SF-Referer - String</t>
               <t>SF-Date - Integer</t>
               <t>SF-Expires - Integer</t>
               <t>SF-IMS - Integer</t>
               <t>SF-IUS - Integer</t>
               <t>SF-LM - Integer</t>
               <t>SF-ETag - Item</t>
               <t>SF-INM - List</t>
               <t>SF-Link - List</t>
               <t>SF-Set-Cookie - Dictionary</t>
               <t>SF-Cookie - List</t>
            </list>
         </t>
      </section>
      <section anchor="security-considerations">
         <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 other implementations 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 fields 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 title="Normative References">
         <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="HTTP">
            <front>
               <title>HTTP Semantics</title>
               <author fullname="Roy T. Fielding">
                  <organization>Adobe</organization>
               </author>
               <author fullname="Mark Nottingham">
                  <organization>Fastly</organization>
               </author>
               <author fullname="Julian Reschke">
                  <organization>greenbytes GmbH</organization>
               </author>
               <date day="12" month="September" year="2021"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-semantics-19"/>
            <x:source basename="draft-ietf-httpbis-semantics-19"
                      href="draft-ietf-httpbis-semantics-19.xml"/>
         </reference>
         <reference anchor="STRUCTURED-FIELDS">
            <front>
               <title>Structured Field Values for HTTP</title>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="P-H. Kamp" initials="P-H." surname="Kamp"/>
               <date month="February" year="2021"/>
            </front>
            <seriesInfo name="RFC" value="8941"/>
            <seriesInfo name="DOI" value="10.17487/RFC8941"/>
         </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="RFC8288">
            <front>
               <title>Web Linking</title>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <date month="October" year="2017"/>
            </front>
            <seriesInfo name="RFC" value="8288"/>
            <seriesInfo name="DOI" value="10.17487/RFC8288"/>
         </reference>
         <reference anchor="RFC6265">
            <front>
               <title>HTTP State Management Mechanism</title>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="April" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6265"/>
            <seriesInfo name="DOI" value="10.17487/RFC6265"/>
         </reference>
      </references>
      <section anchor="numbers">
         <name>Data Supporting Field Compatibility</name>
         <t>To help guide decisions about compatible fields, the HTTP response headers captured by the HTTP Archive <eref target="https://httparchive.org">https://httparchive.org</eref> in September 2021 (representing more than 528,000,000 HTTP exchanges) were parsed as Structured Fields using the types listed in <xref target="compatible"/>, with the indicated number of successful header instances, failures, and the resulting failure rate:</t>
         <figure>
            <artwork>
accept                                 9,099 /        34 =   0.372%*
accept-encoding                      116,708 /        58 =   0.050%*
accept-language                      127,710 /        95 =   0.074%*
accept-patch                             281 /         0 =   0.000%
accept-ranges                    289,341,375 /     7,776 =   0.003%
access-control-allow-credentials  36,159,371 /     2,671 =   0.007%
access-control-allow-headers      25,980,519 /    23,181 =   0.089%
access-control-allow-methods      32,071,437 /    17,424 =   0.054%
access-control-allow-origin      165,719,859 /   130,247 =   0.079%
access-control-expose-headers     20,787,683 /     1,973 =   0.009%
access-control-max-age             9,549,494 /     9,846 =   0.103%
access-control-request-headers       165,882 /       503 =   0.302%*
access-control-request-method        346,135 /    30,680 =   8.142%*
age                              107,395,872 /    36,649 =   0.034%
allow                                579,822 /       281 =   0.048%
alt-svc                           56,773,977 / 4,914,119 =   7.966%
cache-control                    395,402,834 / 1,146,080 =   0.289%
connection                       112,017,641 /     3,491 =   0.003%
content-encoding                 225,568,224 /       237 =   0.000%
content-language                   3,339,291 /     1,744 =   0.052%
content-length                   422,415,406 /       126 =   0.000%
content-type                     503,950,894 /   507,133 =   0.101%
cross-origin-resource-policy     102,483,430 /       799 =   0.001%
expect                                     0 /        53 = 100.000%*
expect-ct                         54,129,244 /    80,333 =   0.148%
host                                  57,134 /     1,486 =   2.535%*
keep-alive                        50,606,877 /     1,509 =   0.003%
origin                                32,438 /     1,396 =   4.126%*
pragma                            66,321,848 /    97,328 =   0.147%
preference-applied                       189 /         0 =   0.000%
referrer-policy                   14,274,787 /     8,091 =   0.057%
retry-after                          523,533 /     7,585 =   1.428%
surrogate-control                    282,846 /       976 =   0.344%
te                                         1 /         0 =   0.000%
timing-allow-origin               91,979,983 /         8 =   0.000%
trailer                                1,171 /         0 =   0.000%
transfer-encoding                 15,098,518 /         0 =   0.000%
vary                             246,483,644 /    69,607 =   0.028%
x-content-type-options           166,063,072 /   237,255 =   0.143%
x-frame-options                   56,863,322 / 1,014,464 =   1.753%
x-xss-protection                 132,739,109 /   347,133 =   0.261%
</artwork>
         </figure>
         <t>Note that this data set only includes response headers, although some request headers are present, indicated with an asterisk (because, the Web). Also, Dictionary and Parameter keys have not been force-lowercased, with the result that any values containing uppercase keys are considered to fail.</t>
         <t>The top thirty header fields in that data set that were not considered compatible are (* indicates that the field is mapped in <xref target="mapped"/>):</t>
         <t>
            <list style="symbols">
               <t>*date: 524,810,577</t>
               <t>server: 470,777,294</t>
               <t>*last-modified: 383,437,099</t>
               <t>*expires: 292,109,781</t>
               <t>*etag: 255,788,799</t>
               <t>strict-transport-security: 111,993,787</t>
               <t>x-cache: 70,713,258</t>
               <t>via: 55,983,914</t>
               <t>cf-ray: 54,556,881</t>
               <t>p3p: 54,479,183</t>
               <t>report-to: 54,056,804</t>
               <t>cf-cache-status: 53,536,789</t>
               <t>nel: 44,815,769</t>
               <t>x-powered-by: 37,281,354</t>
               <t>content-security-policy-report-only: 33,104,387</t>
               <t>*location: 30,533,957</t>
               <t>x-amz-cf-pop: 28,549,182</t>
               <t>x-amz-cf-id: 28,444,359</t>
               <t>content-security-policy: 25,404,401</t>
               <t>x-served-by: 23,277,252</t>
               <t>x-cache-hits: 21,842,899</t>
               <t>*link: 20,761,372</t>
               <t>x-timer: 18,780,130</t>
               <t>content-disposition: 18,516,671</t>
               <t>x-request-id: 16,048,668</t>
               <t>referrer-policy: 15,596,734</t>
               <t>x-cdn: 10,153,756</t>
               <t>x-amz-version-id: 9,786,024</t>
               <t>x-amz-request-id: 9,680,689</t>
               <t>x-dc: 9,557,728</t>
            </list>
         </t>
      </section>
   </back>
</rfc>
