<?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.13 -->
<?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-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-02"
     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</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>
      <date year="2019" month="11" day="4"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract>
         <t>To aid debugging, HTTP caches often append headers to a response detailing how they handled the request. This specification codifies that practice and updates it for HTTP’s current caching model.</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.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" title="Introduction">
         <t>To aid debugging, HTTP caches often append headers to a response detailing how they handled the request.</t>
         <t>Unfortunately, the semantics of these headers are often unclear, and both the semantics and syntax used vary greatly between implementations.</t>
         <t>This specification defines a single, new HTTP response header field, “Cache-Status” for this purpose.</t>
         <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 ABNF as defined in <xref target="RFC5234"/>, along with the “%s” extension for case sensitivity defined in <xref target="RFC7405"/>.</t>
         </section>
      </section>
      <section anchor="the-cache-status-http-response-header"
               title="The Cache-Status HTTP Response Header">
         <t>The Cache-Status HTTP response header indicates caches’ handling of the request corresponding to the response it occurs within.</t>
         <t>Its value is a List <xref target="I-D.ietf-httpbis-header-structure"/>:</t>
         <figure>
            <artwork type="abnf">
Cache-Status   = sh-list
</artwork>
         </figure>
         <t>Each member of the parameterised 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 agent (possibly including the user agent’s cache itself, if it chooses to append a value).</t>
         <t>Caches determine when it is appropriate to add the Cache-Status header field to a response. Some might decide to add it to all responses, whereas others might only do so when specifically configured to, or when the request contains a header that activates a debugging mode.</t>
         <t>When adding a value to the Cache-Status header field, caches SHOULD preserve the existing contents of the header, to allow debugging of the entire chain of caches handling the request.</t>
         <t>The list members identify the cache that inserted the value, and MUST have a type of either sh-string or sh-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”), and IP address, or a generated string.</t>
         <t>Each member of the list can also have a number of parameters that describe that cache’s handling of the request. While all of these parameters are OPTIONAL, caches are encouraged to provide as much information as possible.</t>
         <figure>
            <artwork type="abnf">
fwd           = sh-token
fwd-res       = sh-token
fwd-stored    = sh-boolean
res-fresh     = sh-integer
cache-fresh   = sh-integer
collapse-hit  = sh-boolean
collapse-wait = sh-integer
key           = sh-string
</artwork>
         </figure>
         <section anchor="the-fwd-parameter" title="The fwd parameter">
            <t>“fwd” indicates why the request went forward. If it is not present, the value defaults to “none”.</t>
            <t>It can have one of the following values:</t>
            <t>
               <list style="symbols">
                  <t>none - The request did not go forward; i.e., it was a hit, and was served from the cache.</t>
                  <t>bypass - The cache was configured to not handle this request</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.</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>res-stale - The cache was able to select a response for the request, but it was stale</t>
                  <t>req-stale - The cache was able to select a fresh response for the request, but client request headers (e.g., Cache-Control request directives) did not allow its use</t>
               </list>
            </t>
         </section>
         <section anchor="the-fwd-res-parameter" title="The fwd-res parameter">
            <t>“fwd-res” indicates what the result of the forward request was. It is only valid when fwd is “res-stale” or “req-stale”, and defaults to “full” if not present when fwd is one of those values.</t>
            <t>It can have one of the following values:</t>
            <t>
               <list style="symbols">
                  <t>full - indicates that the response was a complete response (any status code except 304 Not Modified and 206 Partial Response)</t>
                  <t>partial - indicates that the response was a 206 Partial Response</t>
                  <t>notmod - indicates that the response was a 304 Not Modified</t>
               </list>
            </t>
         </section>
         <section anchor="the-fwd-stored-parameter" title="The fwd-stored parameter">
            <t>“fwd-stored” indicates whether the cache stored the response; a true value indicates that it did. Only valid when fwd is not “none”.</t>
         </section>
         <section anchor="the-res-fresh-parameter" title="The res-fresh parameter">
            <t>“res-fresh” indicates the response’s remaining freshness lifetime (as per <xref target="I-D.ietf-httpbis-cache" x:fmt="," x:sec="4.2.1"/>), as an integer number of seconds. This does not include freshness assigned by the cache (see “cache-fresh”). May be negative, to indicate staleness.</t>
         </section>
         <section anchor="the-cache-fresh-parameter" title="The cache-fresh parameter">
            <t>“cache-fresh” indicates the response’s remaining freshness lifetime as calculated by the cache, as an integer number of seconds. This includes freshness assigned by the cache; e.g., through heuristics, local configuration, or other factors. May be negative, to indicate staleness.</t>
            <t>If both cache-fresh and res-fresh appear as parameters on the same value, it implies that the cache freshness overrode the response freshness.</t>
         </section>
         <section anchor="the-collapse-hit-parameter" title="The collapse-hit parameter">
            <t>“collapse-hit” indicates whether this request was collapsed together with one or more other forward requests; 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.</t>
         </section>
         <section anchor="the-collapse-wait-parameter"
                  title="The collapse-wait parameter">
            <t>“collapse-wait” indicates the amount of time that the cache held the request while waiting to see if it could be successfully collapsed, as an integer number of milliseconds.</t>
         </section>
         <section anchor="the-key-parameter" title="The key parameter">
            <t>“key” conveys a representation of the cache key used for the response. Note that this may be implementation-specific.</t>
         </section>
      </section>
      <section anchor="examples" title="Examples">
         <t>The most minimal cache hit:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache
</artwork>
         </figure>
         <t>… but a polite cache will give some more information, e.g.:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; res-fresh=376
</artwork>
         </figure>
         <t>A “negative” hit (i.e., the cache imposed its own freshness lifetime):</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; cache-fresh=415
</artwork>
         </figure>
         <t>A stale hit just has negative freshness:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; res-fresh=-412
</artwork>
         </figure>
         <t>Whereas a complete miss is:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; fwd=uri-miss
</artwork>
         </figure>
         <t>A miss that validated on the back-end server:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; fwd=res-stale; fwd-res=notmod
</artwork>
         </figure>
         <t>A miss that was collapsed with another request:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; fwd=uri-miss; collapse-hit=?1
</artwork>
         </figure>
         <t>A miss that the cache attempted to collapse, but couldn’t:</t>
         <figure>
            <artwork type="example">
Cache-Status: ExampleCache; fwd=uri-miss;
              collapse-hit=?0; collapse-wait=240
</artwork>
         </figure>
         <t>Going through two layers of caching, both of which were hits, and the second collapsed with other requests:</t>
         <figure>
            <artwork type="example">
Cache-Status: "CDN Company Here"; res-fresh=545,
              OriginCache; cache-fresh=1100; collapse-hit=?1
</artwork>
         </figure>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>Information about a cache’s content can be used to infer the activity of those using it. Generally, access to sensitive information in a cache is limited to those who are authorised to access that information (using a variety of techniques), so this does not represent an attack vector in the general sense.</t>
         <t>However, if the Cache-Status header is exposed to parties who are not authorised to obtain the response it occurs within, it could expose information about that data.</t>
         <t>For example, if an attacker were able to obtain the Cache-Status header from a response containing sensitive information and access were limited to one person (or limited set of people), they could determine whether that information had been accessed before. This is similar to the information exposed by various timing attacks, but is arguably more reliable, since the cache is directly reporting its state.</t>
         <t>Mitigations include use of encryption (e.g., TLS <xref target="RFC8446"/>)) to protect the response, and careful controls over access to response headers (as are present in the Web platform). When in doubt, the Cache-Status header field can be omitted.</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="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="RFC7405">
            <front>
               <title>Case-Sensitive String Support in ABNF</title>
               <author fullname="P. Kyzivat" initials="P." surname="Kyzivat"/>
               <date month="December" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7405"/>
            <seriesInfo name="DOI" value="10.17487/RFC7405"/>
         </reference>
         <reference anchor="I-D.ietf-httpbis-header-structure">
            <front>
               <title>Structured Headers for HTTP</title>
               <author fullname="Mark Nottingham" initials="M" surname="Nottingham"/>
               <author fullname="Poul-Henning Kamp" initials="P" surname="Kamp"/>
               <date day="31" month="October" year="2019"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-header-structure-14"/>
         </reference>
         <reference anchor="I-D.ietf-httpbis-cache">
            <front>
               <title>HTTP Caching</title>
               <author fullname="Roy Fielding" initials="R" surname="Fielding"/>
               <author fullname="Mark Nottingham" initials="M" surname="Nottingham"/>
               <author fullname="Julian Reschke" initials="J" surname="Reschke"/>
               <date day="8" month="July" year="2019"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-httpbis-cache-05"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="RFC8446">
            <front>
               <title>The Transport Layer Security (TLS) Protocol Version 1.3</title>
               <author fullname="E. Rescorla" initials="E." surname="Rescorla"/>
               <date month="August" year="2018"/>
            </front>
            <seriesInfo name="RFC" value="8446"/>
            <seriesInfo name="DOI" value="10.17487/RFC8446"/>
         </reference>
      </references>
   </back>
</rfc>
