<?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.6 -->
<?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-cache-header-10"
     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 abbrev="Cache-Status Header">The Cache-Status HTTP Response Header Field</title>
      <author fullname="Mark Nottingham" initials="M." surname="Nottingham">
         <organization>Fastly</organization>
         <address>
            <postal>
               <city>Prahran</city>
               <region>VIC</region>
               <country>Australia</country>
            </postal>
            <email>mnot@mnot.net</email>
            <uri>https://www.mnot.net/</uri>
         </address>
      </author>
      <date year="2021" month="August" day="17"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>http</keyword>
      <keyword>cache</keyword>
      <keyword>debugging</keyword>
      <keyword>x-cache</keyword>
      <abstract>
         <t>To aid debugging, HTTP caches often append header fields to a response explaining how they handled the request in an ad hoc manner. This specification defines a standard mechanism to do so that is aligned with HTTP's caching model.</t>
      </abstract>
      <note title="Note to Readers">
         <t>
            <em>RFC EDITOR: please remove this section before publication</em>
         </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.org/">https://httpwg.org/</eref>; source code and issues list for this draft can be found at <eref target="https://github.com/httpwg/http-extensions/labels/cache-header">https://github.com/httpwg/http-extensions/labels/cache-header</eref>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>To aid debugging (both by humans and automated tools), HTTP caches often append header fields to a response explaining how they handled the request. Unfortunately, the semantics of these headers are often unclear, and both the semantics and syntax used vary between implementations.</t>
         <t>This specification defines a new HTTP response header field, "Cache-Status" for this purpose, with standardized syntax and semantics.</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>
            <t>This document uses ABNF as defined in <xref target="RFC5234"/>, with rules prefixed with "sf-" and the "key" rule as defined in <xref target="STRUCTURED-FIELDS"/>. It uses terminology from <xref target="HTTP"/> and <xref target="HTTP-CACHING"/>.</t>
         </section>
      </section>
      <section anchor="field">
         <name>The Cache-Status HTTP Response Header Field</name>
         <t>The Cache-Status HTTP response header field indicates how caches have handled that response and its corresponding request. The syntax of this header field conforms to <xref target="STRUCTURED-FIELDS"/>.</t>
         <t>Its value is a List (<xref section="3.1" sectionFormat="comma" target="STRUCTURED-FIELDS"/>):</t>
         <figure>
            <sourcecode type="abnf">
Cache-Status   = sf-list
</sourcecode>
         </figure>
         <t>Each member of the list represents a cache that has handled the request. The first member of the list represents the cache closest to the origin server, and the last member of the list represents the cache closest to the user (possibly including the user agent's cache itself, if it appends a value).</t>
         <t>Caches determine when it is appropriate to add the Cache-Status header field to a response. Some might add it to all responses, whereas others might only do so when specifically configured to, or when the request contains a header field that activates a debugging mode. See <xref target="security"/> for related security considerations.</t>
         <t>An intermediary SHOULD NOT append a Cache-Status member to responses that it generates locally, even if that intermediary contains a cache, unless the generated response is based upon a stored response (e.g., 304 Not Modified and 206 Partial Content are both based upon a stored response). For example, a proxy generating a 400 response due to a malformed request will not add a Cache-Status value, because that response was generated by the proxy, not the origin server.</t>
         <t>When adding a value to the Cache-Status header field, caches SHOULD preserve the existing field value, to allow debugging of the entire chain of caches handling the request.</t>
         <t>Each list member identifies the cache that inserted it and this identifier MUST be a String or Token. Depending on the deployment, this might be a product or service name (e.g., ExampleCache or "Example CDN"), a hostname ("cache-3.example.com"), an IP address, or a generated string.</t>
         <t>Each member of the list can have parameters that describe that cache's handling of the request. While these parameters are OPTIONAL, caches are encouraged to provide as much information as possible.</t>
         <t>This specification defines the following parameters:</t>
         <figure>
            <sourcecode type="abnf">
hit          = sf-boolean
fwd          = sf-token
fwd-status   = sf-integer
ttl          = sf-integer
stored       = sf-boolean
collapsed    = sf-boolean
key          = sf-string
detail       = sf-token / sf-string
</sourcecode>
         </figure>
         <section anchor="the-hit-parameter">
            <name>The hit parameter</name>
            <t>"hit", when true, indicates that the request was satisfied by the cache; i.e., it was not forwarded, and the response was obtained from the cache.</t>
            <t>A response that was originally produced by the origin but was modified by the cache (for example, a 304 or 206 status code) is still considered a hit, as long as it did not go forward (e.g., for validation).</t>
            <t>A response that was in cache but not able to be used without going forward (e.g., because it was stale, or partial) is not considered a hit. Note that a stale response that is used without going forward (e.g., because the origin server is not available) can be considered a hit.</t>
            <t>"hit" and "fwd" are exclusive; only one of them should appear on each list member.</t>
         </section>
         <section anchor="the-fwd-parameter">
            <name>The fwd parameter</name>
            <t>"fwd" indicates that the request went forward towards the origin, and why.</t>
            <t>The following parameter values are defined to explain why the request went forward, from most specific to least:</t>
            <t>
               <list style="symbols">
                  <t>bypass - The cache was configured to not handle this request</t>
                  <t>method - The request method's semantics require the request to be forwarded</t>
                  <t>uri-miss - The cache did not contain any responses that matched the request URI</t>
                  <t>vary-miss - The cache contained a response that matched the request URI, but could not select a response based upon this request's headers and stored Vary headers.</t>
                  <t>miss - The cache did not contain any responses that could be used to satisfy this request (to be used when an implementation cannot distinguish between uri-miss and vary-miss)</t>
                  <t>request - The cache was able to select a fresh response for the request, but the request's semantics (e.g., Cache-Control request directives) did not allow its use</t>
                  <t>stale - The cache was able to select a response for the request, but it was stale</t>
                  <t>partial - The cache was able to select a partial response for the request, but it did not contain all of the requested ranges (or the request was for the complete response)</t>
               </list>
            </t>
            <t>The most specific reason that the cache is aware of SHOULD be used, to the extent that it is possible to implement. See also <xref section="4" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor constructing.responses.from.caches?><?aug-title Constructing Responses from Caches?></xref>.</t>
         </section>
         <section anchor="the-fwd-status-parameter">
            <name>The fwd-status parameter</name>
            <t>"fwd-status" indicates what status code (see <xref section="15" sectionFormat="comma" target="HTTP"><?aug-anchor status.codes?><?aug-title Status Codes?></xref>) the next hop server returned in response to the forwarded request. Only meaningful when "fwd" is present; if "fwd-status" is not present but "fwd" is, it defaults to the status code sent in the response.</t>
            <t>This parameter is useful to distinguish cases when the next hop server sends a 304 Not Modified response to a conditional request, or a 206 Partial Response because of a range request.</t>
         </section>
         <section anchor="the-ttl-parameter">
            <name>The ttl parameter</name>
            <t>"ttl" indicates the response's remaining freshness lifetime (see <xref section="4.2.1" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor calculating.freshness.lifetime?><?aug-title Calculating Freshness Lifetime?></xref>) as calculated by the cache, as an integer number of seconds, measured as closely as possible to when the response header section is sent by the cache. This includes freshness assigned by the cache; e.g., through heuristics (see <xref section="4.2.2" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor heuristic.freshness?><?aug-title Calculating Heuristic Freshness?></xref>), local configuration, or other factors. May be negative, to indicate staleness.</t>
         </section>
         <section anchor="the-stored-parameter">
            <name>The stored parameter</name>
            <t>"stored" indicates whether the cache stored the response (see <xref section="3" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor response.cacheability?><?aug-title Storing Responses in Caches?></xref>); a true value indicates that it did. Only meaningful when fwd is present.</t>
         </section>
         <section anchor="the-collapsed-parameter">
            <name>The collapsed parameter</name>
            <t>"collapsed" indicates whether this request was collapsed together with one or more other forward requests (see <xref section="4" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor constructing.responses.from.caches?><?aug-title Constructing Responses from Caches?></xref>); if true, the response was successfully reused; if not, a new request had to be made. If not present, the request was not collapsed with others. Only meaningful when fwd is present.</t>
         </section>
         <section anchor="the-key-parameter">
            <name>The key parameter</name>
            <t>"key" conveys a representation of the cache key (see <xref section="2" sectionFormat="comma" target="HTTP-CACHING"><?aug-anchor caching.overview?><?aug-title Overview of Cache Operation?></xref>) used for the response. Note that this may be implementation-specific.</t>
         </section>
         <section anchor="the-detail-parameter">
            <name>The detail parameter</name>
            <t>"detail" allows implementations to convey additional information not captured in other parameters; for example, implementation-specific states, or other caching-related metrics.</t>
            <t>For example:</t>
            <figure>
               <sourcecode type="http-message">
Cache-Status: ExampleCache; hit; detail=MEMORY
</sourcecode>
            </figure>
            <t>The semantics of a detail parameter are always specific to the cache that sent it; even if a member of details from another cache shares the same name, it might not mean the same thing.</t>
            <t>This parameter is intentionally limited. If an implementation's developer or operator needs to convey additional information in an interoperable fashion, they are encouraged to register extension parameters (see <xref target="register"/>) or define another header field.</t>
         </section>
      </section>
      <section anchor="examples">
         <name>Examples</name>
         <t>The most minimal cache hit:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; hit
</sourcecode>
         </figure>
         <t>... but a polite cache will give some more information, e.g.:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; hit; ttl=376
</sourcecode>
         </figure>
         <t>A stale hit just has negative freshness:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; hit; ttl=-412
</sourcecode>
         </figure>
         <t>Whereas a complete miss is:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; fwd=uri-miss
</sourcecode>
         </figure>
         <t>A miss that successfully validated on the back-end server:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; fwd=stale; fwd-status=304
</sourcecode>
         </figure>
         <t>A miss that was collapsed with another request:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; fwd=uri-miss; collapsed
</sourcecode>
         </figure>
         <t>A miss that the cache attempted to collapse, but couldn't:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ExampleCache; fwd=uri-miss; collapsed=?0
</sourcecode>
         </figure>
         <t>Going through two separate layers of caching, where the cache closest to the origin responded to an earlier request with a stored response, and a second cache stored that response and later reused it to satisfy the current request:</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: OriginCache; hit; ttl=1100,
              "CDN Company Here"; hit; ttl=545
</sourcecode>
         </figure>
         <t>Going through a three-layer caching system, where the closest to the origin is a reverse proxy (where the response was served from cache), the next is a forward proxy interposed by the network (where the request was forwarded because there wasn't any response cached with its URI, the request was collapsed with others, and the resulting response was stored), and the closest to the user is a browser cache (where there wasn't any response cached with the request's URI):</t>
         <figure>
            <sourcecode type="http-message">
Cache-Status: ReverseProxyCache; hit
Cache-Status: ForwardProxyCache; fwd=uri-miss; collapsed; stored
Cache-Status: BrowserCache; fwd=uri-miss
</sourcecode>
         </figure>
      </section>
      <section anchor="register">
         <name>Defining New Cache-Status Parameters</name>
         <t>New Cache-Status Parameters can be defined by registering them in the HTTP Cache-Status Parameters registry.</t>
         <t>Registration requests are reviewed and approved by a Designated Expert, as per <xref section="4.5" sectionFormat="comma" target="RFC8126"/>. A specification document is appreciated, but not required.</t>
         <t>The Expert(s) should consider the following factors when evaluating requests:</t>
         <t>
            <list style="symbols">
               <t>Community feedback</t>
               <t>If the value is sufficiently well-defined</t>
               <t>Generic parameters are preferred over vendor-specific, application-specific, or deployment-specific values. If a generic value cannot be agreed upon in the community, the parameter's name should be correspondingly specific (e.g., with a prefix that identifies the vendor, application or deployment).</t>
            </list>
         </t>
         <t>Registration requests should use the following template:</t>
         <t>
            <list style="symbols">
               <t>Name: [a name for the Cache-Status Parameter that matches the 'key' ABNF rule]</t>
               <t>Description: [a description of the parameter semantics and value]</t>
               <t>Reference: [to a specification defining this parameter, if available]</t>
            </list>
         </t>
         <t>See the registry at <eref target="https://iana.org/assignments/http-cache-status">https://iana.org/assignments/http-cache-status</eref> for details on where to send registration requests.</t>
      </section>
      <section anchor="iana-considerations">
         <name>IANA Considerations</name>
         <t>Upon publication, please create the HTTP Cache-Status Parameters registry at <eref target="https://iana.org/assignments/http-cache-status">https://iana.org/assignments/http-cache-status</eref> and populate it with the types defined in <xref target="field"/>; see <xref target="register"/> for its associated procedures.</t>
         <t>Also, please create the following entry in the Hypertext Transfer Protocol (HTTP) Field Name Registry defined in <xref section="18.4" sectionFormat="comma" target="HTTP"><?aug-anchor field.name.registration?><?aug-title Field Name Registration?></xref>:</t>
         <t>
            <list style="symbols">
               <t>Field name: Cache-Status</t>
               <t>Status: permanent</t>
               <t>Specification document: [this document]</t>
               <t>Comments:</t>
            </list>
         </t>
      </section>
      <section anchor="security">
         <name>Security Considerations</name>
         <t>Attackers can use the information in Cache-Status to probe the behaviour of the cache (and other components), and infer the activity of those using the cache. The Cache-Status header field may not create these risks on its own, but can assist attackers in exploiting them.</t>
         <t>For example, knowing if a cache has stored a response can help an attacker execute a timing attack on sensitive data.</t>
         <t>Additionally, exposing the cache key can help an attacker understand modifications to the cache key, which may assist cache poisoning attacks. See <xref target="ENTANGLE"/> for details.</t>
         <t>The underlying risks can be mitigated with a variety of techniques (e.g., use of encryption and authentication; avoiding the inclusion of attacker-controlled data in the cache key), depending on their exact nature. Note that merely obfuscating the key does not mitigate this risk.</t>
         <t>To avoid assisting such attacks, the Cache-Status header field can be omitted, only sent when the client is authorized to receive it, or only send sensitive information (e.g., the key parameter) when the client is authorized.</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="RFC8126">
            <front>
               <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
               <author fullname="M. Cotton" initials="M." surname="Cotton"/>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <author fullname="T. Narten" initials="T." surname="Narten"/>
               <date month="June" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="26"/>
            <seriesInfo name="RFC" value="8126"/>
            <seriesInfo name="DOI" value="10.17487/RFC8126"/>
         </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="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="25" month="July" year="2021"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-semantics-17"/>
            <x:source basename="draft-ietf-httpbis-semantics-17"
                      href="draft-ietf-httpbis-semantics-17.xml"/>
         </reference>
         <reference anchor="HTTP-CACHING">
            <front>
               <title>HTTP Caching</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="25" month="July" year="2021"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-cache-17"/>
            <x:source basename="draft-ietf-httpbis-cache-17"
                      href="draft-ietf-httpbis-cache-17.xml"/>
         </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>
      </references>
      <references title="Informative References">
         <reference anchor="ENTANGLE"
                    target="https://i.blackhat.com/USA-20/Wednesday/us-20-Kettle-Web-Cache-Entanglement-Novel-Pathways-To-Poisoning-wp.pdf">
            <front>
               <title>Web Cache Entanglement: Novel Pathways to Poisoning</title>
               <author fullname="James Kettle" initials="J." surname="Kettle">
                  <organization>PortSwigger</organization>
               </author>
               <date year="2020"/>
            </front>
         </reference>
      </references>
   </back>
</rfc>
