<?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="exp"
     docName="draft-ietf-httpbis-cache-digest-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>Cache Digests for HTTP/2</title>
      <author fullname="Kazuho Oku" initials="K." surname="Oku">
         <organization>Fastly</organization>
         <address>
            <email>kazuhooku@gmail.com</email>
         </address>
      </author>
      <author fullname="Yoav Weiss" initials="Y." surname="Weiss">
         <organization>Akamai</organization>
         <address>
            <email>yoav@yoav.ws</email>
            <uri>https://blog.yoav.ws/</uri>
         </address>
      </author>
      <date/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract><?line 61?>
         <t>This specification defines a HTTP/2 frame type to allow clients to inform the server of their cache's contents. Servers can then use this to inform their choices of what to push to clients.</t>
      </abstract>
      <note title="Note to Readers"><?line 67?>
         <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="http://httpwg.github.io/">http://httpwg.github.io/</eref>; source code and issues list for this draft can be found at <eref target="https://github.com/httpwg/http-extensions/labels/cache-digest">https://github.com/httpwg/http-extensions/labels/cache-digest</eref>.</t>
      </note>
   </front>
   <middle><?line 75?>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>HTTP/2 <xref target="RFC7540"/> allows a server to "push" synthetic request/response pairs into a client's cache optimistically. While there is strong interest in using this facility to improve perceived Web browsing performance, it is sometimes counterproductive because the client might already have cached the "pushed" response.</t>
         <t>When this is the case, the bandwidth used to "push" the response is effectively wasted, and represents opportunity cost, because it could be used by other, more relevant responses. HTTP/2 allows a stream to be cancelled by a client using a RST_STREAM frame in this situation, but there is still at least one round trip of potentially wasted capacity even then.</t>
         <t>This specification defines a HTTP/2 frame type to allow clients to inform the server of their freshly cached contents using a Cuckoo-filter <xref target="Cuckoo"/> based digest. Servers can then use this to inform their choices of what to push to clients.</t>
         <section anchor="notational-conventions">
            <name>Notational Conventions</name>
            <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target="RFC2119"/>.</t>
         </section>
      </section>
      <section anchor="the-cachedigest-frame">
         <name>The CACHE_DIGEST Frame</name>
         <t>The CACHE_DIGEST frame type is 0xd (decimal 13).</t>
         <figure>
            <artwork>
+-------------------------------+-------------------------------+
|         Origin-Len (16)       | Origin? (\*)                ...
+-------------------------------+-------------------------------+
|                   Digest-Value? (\*)                        ...
+---------------------------------------------------------------+
</artwork>
         </figure>
         <t>The CACHE_DIGEST frame payload has the following fields:</t>
         <dl>
            <dt>Origin-Len:</dt>
            <dd>
               <t>An unsigned, 16-bit integer indicating the length, in octets, of the Origin field.</t>
            </dd>
            <dt>Origin:</dt>
            <dd>
               <t>A sequence of characters containing the ASCII serialization of an origin (<xref target="RFC6454" x:fmt="," x:sec="6.2"/>) that the Digest-Value applies to.</t>
            </dd>
            <dt>Digest-Value:</dt>
            <dd>
               <t>A sequence of octets containing the digest as computed in <xref target="creating"/> and <xref target="adding"/>.</t>
            </dd>
         </dl>
         <t>The CACHE_DIGEST frame defines the following flags:</t>
         <t>
            <list style="symbols">
               <t>
                  <strong>RESET</strong> (0x1): When set, indicates that any and all cache digests for the applicable origin held by the recipient MUST be considered invalid.</t>
               <t>
                  <strong>COMPLETE</strong> (0x2): When set, indicates that the currently valid set of cache digests held by the server constitutes a complete representation of the cache's state regarding that origin.</t>
            </list>
         </t>
         <section anchor="client-behavior">
            <name>Client Behavior</name>
            <t>A CACHE_DIGEST frame MUST be sent from a client to a server on stream 0, and conveys a digest of the contents of the client's cache for the indicated origin.</t>
            <t>In typical use, a client will send one or more CACHE_DIGESTs immediately after the first request on a connection for a given origin, on the same stream, because there is usually a short period of inactivity then, and servers can benefit most when they understand the state of the cache before they begin pushing associated assets (e.g., CSS, JavaScript and images). Clients MAY send CACHE_DIGEST at other times.</t>
            <t>If the cache's state is cleared, lost, or the client otherwise wishes the server to stop using previously sent CACHE_DIGESTs, it can send a CACHE_DIGEST with the RESET flag set.</t>
            <t>When generating CACHE_DIGEST, a client MUST NOT include stale-cached responses or responses whose URLs do not share origins <xref target="RFC6454"/> with the indicated origin. Clients MUST NOT send CACHE_DIGEST frames on connections that are not authoritative (as defined in <xref target="RFC7540"/>, 10.1) for the indicated origin.</t>
            <t>When the CACHE_DIGEST frames sent represent the complete set of stored responses, the last such frame SHOULD have a COMPLETE flag set, to indicate to the server that it has all relevant state. Note that for the purposes of COMPLETE, responses cached since the beginning of the connection or the last RESET flag on a CACHE_DIGEST frame need not be included.</t>
            <t>CACHE_DIGEST has no defined meaning when sent from servers, and SHOULD be ignored by clients.</t>
            <section anchor="creating">
               <name>Creating a digest</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">P</spanx>, an integer smaller than 256, that indicates the probability of a false positive that is acceptable, expressed as <spanx style="verb">1/2\*\*P</spanx>.</t>
                     <t>
                        <spanx style="verb">N</spanx>, an integer that represents the number of entries - a prime number smaller than 2**32</t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">f</spanx> be the number of bits per fingerprint, calculated as <spanx style="verb">P + 3</spanx>
                     </t>
                     <t>Let <spanx style="verb">b</spanx> be the bucket size, defined as 4.</t>
                     <t>Let <spanx style="verb">allocated</spanx> be the closest power of 2 that is larger than <spanx style="verb">N</spanx>.</t>
                     <t>Let <spanx style="verb">bytes</spanx> be <spanx style="verb">f</spanx>*<spanx style="verb">allocated</spanx>*<spanx style="verb">b</spanx>/8 rounded up to the nearest integer</t>
                     <t>Add 5 to <spanx style="verb">bytes</spanx>
                     </t>
                     <t>Allocate memory of <spanx style="verb">bytes</spanx> and set it to zero. Assign it to <spanx style="verb">digest-value</spanx>.</t>
                     <t>Set the first byte to <spanx style="verb">P</spanx>
                     </t>
                     <t>Set the second till fifth bytes to <spanx style="verb">N</spanx> in big endian form</t>
                     <t>Return the <spanx style="verb">digest-value</spanx>.</t>
                  </list>
               </t>
               <t>Note: <spanx style="verb">allocated</spanx> is necessary due to the nature of the way Cuckoo filters are creating the secondary hash, by XORing the initial hash and the fingerprint's hash. The XOR operation means that secondary hash can pick an entry beyond the initial number of entries, up to the next power of 2. In order to avoid issues there, we allocate the table appropriately. For increased space efficiency, it is recommended that implementations pick a number of entries that's close to the next power of 2.</t>
            </section>
            <section anchor="adding">
               <name>Adding a URL to the Digest-Value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">URL</spanx> a string corresponding to the Effective Request URI (<xref target="RFC7230" x:fmt="," x:sec="5.5"/>) of a cached response <xref target="RFC7234"/>
                     </t>
                     <t>
                        <spanx style="verb">maxcount</spanx> - max number of cuckoo hops</t>
                     <t>
                        <spanx style="verb">digest-value</spanx>
                     </t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">f</spanx> be the value of the first byte of <spanx style="verb">digest-value</spanx>.</t>
                     <t>Let <spanx style="verb">b</spanx> be the bucket size, defined as 4.</t>
                     <t>Let <spanx style="verb">N</spanx> be the value of the second to fifth bytes of <spanx style="verb">digest-value</spanx> in big endian form.</t>
                     <t>Let <spanx style="verb">key</spanx> be the return value of <xref target="key"/> with <spanx style="verb">URL</spanx> as input.</t>
                     <t>Let <spanx style="verb">h1</spanx> be the return value of <xref target="hash"/> with <spanx style="verb">key</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">dest_fingerprint</spanx> be the return value of <xref target="fingerprint"/> with <spanx style="verb">key</spanx> and <spanx style="verb">f</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">h2</spanx> be the return value of <xref target="hash2"/> with <spanx style="verb">h1</spanx>, <spanx style="verb">dest_fingerprint</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">h</spanx> be either <spanx style="verb">h1</spanx> or <spanx style="verb">h2</spanx>, picked in random.</t>
                     <t>While <spanx style="verb">maxcount</spanx> is larger than zero: <list style="numbers">
                           <t>Let <spanx style="verb">position_start</spanx> be 40 + <spanx style="verb">h</spanx> * <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>Let <spanx style="verb">position_end</spanx> be <spanx style="verb">position_start</spanx> + <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>While <spanx style="verb">position_start</spanx> &lt; <spanx style="verb">position_end</spanx>: <list style="numbers">
                                 <t>Let <spanx style="verb">bits</spanx> be <spanx style="verb">f</spanx> bits from <spanx style="verb">digest_value</spanx> starting at <spanx style="verb">position_start</spanx>.</t>
                                 <t>If <spanx style="verb">bits</spanx> is all zeros, set <spanx style="verb">bits</spanx> to <spanx style="verb">dest_fingerprint</spanx> and terminate these steps.</t>
                                 <t>Add <spanx style="verb">f</spanx> to <spanx style="verb">position_start</spanx>.</t>
                              </list>
                           </t>
                           <t>Let <spanx style="verb">e</spanx> be a random number from 0 to <spanx style="verb">b</spanx>.</t>
                           <t>Subtract <spanx style="verb">f</spanx> * (<spanx style="verb">b</spanx> - <spanx style="verb">e</spanx>) from <spanx style="verb">position_start</spanx>.</t>
                           <t>Let <spanx style="verb">bits</spanx> be <spanx style="verb">f</spanx> bits from <spanx style="verb">digest_value</spanx> starting at <spanx style="verb">position_start</spanx>.</t>
                           <t>Let <spanx style="verb">fingerprint</spanx> be the value of bits, read as big endian.</t>
                           <t>Set <spanx style="verb">bits</spanx> to <spanx style="verb">dest_fingerprint</spanx>.</t>
                           <t>Set <spanx style="verb">dest_fingerprint</spanx> to <spanx style="verb">fingerprint</spanx>.</t>
                           <t>Let <spanx style="verb">h</spanx> be <xref target="hash2"/> with <spanx style="verb">h</spanx>, <spanx style="verb">dest_fingerprint</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                           <t>Subtract 1 from <spanx style="verb">maxcount</spanx>.</t>
                        </list>
                     </t>
                     <t>Subtract <spanx style="verb">f</spanx> from <spanx style="verb">position_start</spanx>.</t>
                     <t>Let <spanx style="verb">fingerprint</spanx> be the <spanx style="verb">f</spanx> bits starting at <spanx style="verb">position_start</spanx>.</t>
                     <t>Let <spanx style="verb">h1</spanx> be <spanx style="verb">h</spanx>
                     </t>
                     <t>Subtract 1 from <spanx style="verb">maxcount</spanx>.</t>
                     <t>If <spanx style="verb">maxcount</spanx> is zero, return an error.</t>
                     <t>Go to step 7.</t>
                  </list>
               </t>
            </section>
            <section anchor="removing">
               <name>Removing a URL to the Digest-Value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">URL</spanx> a string corresponding to the Effective Request URI (<xref target="RFC7230" x:fmt="," x:sec="5.5"/>) of a cached response <xref target="RFC7234"/>
                     </t>
                     <t>
                        <spanx style="verb">digest-value</spanx>
                     </t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">f</spanx> be the value of the first byte of <spanx style="verb">digest-value</spanx>.</t>
                     <t>Let <spanx style="verb">b</spanx> be the bucket size, defined as 4.</t>
                     <t>Let <spanx style="verb">N</spanx> be the value of the second to fifth bytes of <spanx style="verb">digest-value</spanx> in big endian form.</t>
                     <t>Let <spanx style="verb">key</spanx> be the return value of <xref target="key"/> with <spanx style="verb">URL</spanx> as input.</t>
                     <t>Let <spanx style="verb">h1</spanx> be the return value of <xref target="hash"/> with <spanx style="verb">key</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">fingerprint</spanx> be the return value of <xref target="fingerprint"/> with <spanx style="verb">key</spanx> and <spanx style="verb">f</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">h2</spanx> be the return value of <xref target="hash2"/> with <spanx style="verb">h1</spanx>, <spanx style="verb">fingerprint</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">hashes</spanx> be an array containing <spanx style="verb">h1</spanx> and <spanx style="verb">h2</spanx>.</t>
                     <t>For each <spanx style="verb">h</spanx> in <spanx style="verb">hashes</spanx>: <list style="numbers">
                           <t>Let <spanx style="verb">position_start</spanx> be 40 + <spanx style="verb">h</spanx> * <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>Let <spanx style="verb">position_end</spanx> be <spanx style="verb">position_start</spanx> + <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>While <spanx style="verb">position_start</spanx> &lt; <spanx style="verb">position_end</spanx>: <list style="numbers">
                                 <t>Let <spanx style="verb">bits</spanx> be <spanx style="verb">f</spanx> bits from <spanx style="verb">digest_value</spanx> starting at <spanx style="verb">position_start</spanx>.</t>
                                 <t>If <spanx style="verb">bits</spanx> is <spanx style="verb">fingerprint</spanx>, set <spanx style="verb">bits</spanx> to all zeros and terminate these steps.</t>
                                 <t>Add <spanx style="verb">f</spanx> to <spanx style="verb">position_start</spanx>.</t>
                              </list>
                           </t>
                        </list>
                     </t>
                  </list>
               </t>
            </section>
            <section anchor="fingerprint">
               <name>Computing a fingerprint value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">key</spanx>, an array of characters</t>
                     <t>
                        <spanx style="verb">f</spanx>, an integer indicating the number of output bits</t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">hash-value</spanx> be the SHA-256 message digest <xref target="RFC6234"/> of <spanx style="verb">key</spanx>, expressed as an integer.</t>
                     <t>Let <spanx style="verb">h</spanx> be the number of bits in <spanx style="verb">hash-value</spanx>
                     </t>
                     <t>Let <spanx style="verb">fingerprint-value</spanx> be 0</t>
                     <t>While <spanx style="verb">fingerprint-value</spanx> is 0 and <spanx style="verb">h</spanx> &gt; <spanx style="verb">f</spanx>: <list style="numbers">
                           <t>Let <spanx style="verb">fingerprint-value</spanx> be the <spanx style="verb">f</spanx> least significant bits of <spanx style="verb">hash-value</spanx>.</t>
                           <t>Let <spanx style="verb">hash-value</spanx> be the <spanx style="verb">h</spanx>-<spanx style="verb">f</spanx> most significant bits of <spanx style="verb">hash-value</spanx>.</t>
                           <t>Subtract <spanx style="verb">f</spanx> from <spanx style="verb">h</spanx>.</t>
                        </list>
                     </t>
                     <t>If <spanx style="verb">fingerprint-value</spanx> is 0, let <spanx style="verb">fingerprint-value</spanx> be 1.</t>
                     <t>Return <spanx style="verb">fingerprint-value</spanx>.</t>
                  </list>
               </t>
               <t>Note: Step 5 is to handle the extremely unlikely case where a SHA-256 digest of <spanx style="verb">key</spanx> is all zeros. The implications of it means that there's an infitisimaly larger probability of getting a <spanx style="verb">fingerprint-value</spanx> of 1 compared to all other values. This is not a problem for any practical purpose.</t>
            </section>
            <section anchor="key">
               <name>Computing the key</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">URL</spanx>, an array of characters</t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">key</spanx> be <spanx style="verb">URL</spanx> converted to an ASCII string by percent-encoding as appropriate <xref target="RFC3986"/>.</t>
                     <t>Return <spanx style="verb">key</spanx>
                     </t>
                  </list>
               </t>
            </section>
            <section anchor="hash">
               <name>Computing a Hash Value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">key</spanx>, an array of characters.</t>
                     <t>
                        <spanx style="verb">N</spanx>, an integer</t>
                  </list>
               </t>
               <t>
                  <spanx style="verb">hash-value</spanx> can be computed using the following algorithm:</t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">hash-value</spanx> be the SHA-256 message digest <xref target="RFC6234"/> of <spanx style="verb">key</spanx>, truncated to 32 bits, expressed as an integer.</t>
                     <t>Return <spanx style="verb">hash-value</spanx> modulo N.</t>
                  </list>
               </t>
            </section>
            <section anchor="hash2">
               <name>Computing an Alternative Hash Value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">hash1</spanx>, an integer indicating the previous hash.</t>
                     <t>
                        <spanx style="verb">fingerprint</spanx>, an integer indicating the fingerprint value.</t>
                     <t>
                        <spanx style="verb">N</spanx>, an integer indicating the number of entries in the digest.</t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">fingerprint-string</spanx> be the value of <spanx style="verb">fingerprint</spanx> in base 10, expressed as a string.</t>
                     <t>Let <spanx style="verb">hash2</spanx> be the return value of <xref target="hash"/> with <spanx style="verb">fingerprint-string</spanx> and <spanx style="verb">N</spanx> as inputs, XORed with <spanx style="verb">hash1</spanx>.</t>
                     <t>Return <spanx style="verb">hash2</spanx>.</t>
                  </list>
               </t>
            </section>
         </section>
         <section anchor="server-behavior">
            <name>Server Behavior</name>
            <t>In typical use, a server will query (as per <xref target="querying"/>) the CACHE_DIGESTs received on a given connection to inform what it pushes to that client;</t>
            <t>
               <list style="symbols">
                  <t>If a given URL has a match in a current CACHE_DIGEST, a complete response need not be pushed; The server MAY push a 304 response for that resource, indicating the client that it hasn't changed.</t>
                  <t>If a given URL has no match in any current CACHE_DIGEST, the client does not have a cached copy, and a complete response can be pushed.</t>
               </list>
            </t>
            <t>Servers MAY use all CACHE_DIGESTs received for a given origin as current, as long as they do not have the RESET flag set; a CACHE_DIGEST frame with the RESET flag set MUST clear any previously stored CACHE_DIGESTs for its origin. Servers MUST treat an empty Digest-Value with a RESET flag set as effectively clearing all stored digests for that origin.</t>
            <t>Clients are not likely to send updates to CACHE_DIGEST over the lifetime of a connection; it is expected that servers will separately track what cacheable responses have been sent previously on the same connection, using that knowledge in conjunction with that provided by CACHE_DIGEST.</t>
            <t>Servers MUST ignore CACHE_DIGEST frames sent on a stream other than 0.</t>
            <section anchor="querying">
               <name>Querying the Digest for a Value</name>
               <t>Given the following inputs:</t>
               <t>
                  <list style="symbols">
                     <t>
                        <spanx style="verb">URL</spanx> a string corresponding to the Effective Request URI (<xref target="RFC7230" x:fmt="," x:sec="5.5"/>) of a cached response <xref target="RFC7234"/>.</t>
                     <t>
                        <spanx style="verb">digest-value</spanx>, an array of bits.</t>
                  </list>
               </t>
               <t>
                  <list style="numbers">
                     <t>Let <spanx style="verb">f</spanx> be the value of the first byte of <spanx style="verb">digest-value</spanx>.</t>
                     <t>Let <spanx style="verb">b</spanx> be the bucket size, defined as 4.</t>
                     <t>Let <spanx style="verb">N</spanx> be the value of the second to fifth bytes of <spanx style="verb">digest-value</spanx> in big endian form.</t>
                     <t>Let <spanx style="verb">key</spanx> be the return value of <xref target="key"/> with <spanx style="verb">URL</spanx> as input.</t>
                     <t>Let <spanx style="verb">h1</spanx> be the return value of <xref target="hash"/> with <spanx style="verb">key</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">fingerprint</spanx> be the return value of <xref target="fingerprint"/> with <spanx style="verb">key</spanx> and <spanx style="verb">f</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">h2</spanx> be the return value of <xref target="hash2"/> with <spanx style="verb">h1</spanx>, <spanx style="verb">fingerprint</spanx> and <spanx style="verb">N</spanx> as inputs.</t>
                     <t>Let <spanx style="verb">hashes</spanx> be an array containing <spanx style="verb">h1</spanx> and <spanx style="verb">h2</spanx>.</t>
                     <t>For each <spanx style="verb">h</spanx> in <spanx style="verb">hashes</spanx>: <list style="numbers">
                           <t>Let <spanx style="verb">position_start</spanx> be 40 + <spanx style="verb">h</spanx> * <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>Let <spanx style="verb">position_end</spanx> be <spanx style="verb">position_start</spanx> + <spanx style="verb">f</spanx> * <spanx style="verb">b</spanx>.</t>
                           <t>While <spanx style="verb">position_start</spanx> &lt; <spanx style="verb">position_end</spanx>: <list style="numbers">
                                 <t>Let <spanx style="verb">bits</spanx> be <spanx style="verb">f</spanx> bits from <spanx style="verb">digest_value</spanx> starting at <spanx style="verb">position_start</spanx>.</t>
                                 <t>If <spanx style="verb">bits</spanx> is <spanx style="verb">fingerprint</spanx>, return true</t>
                                 <t>Add <spanx style="verb">f</spanx> to <spanx style="verb">position_start</spanx>.</t>
                              </list>
                           </t>
                        </list>
                     </t>
                     <t>Return false.</t>
                  </list>
               </t>
            </section>
         </section>
      </section>
      <section anchor="the-settingssendingcachedigest-settings-parameter">
         <name>The SETTINGS_SENDING_CACHE_DIGEST SETTINGS Parameter</name>
         <t>A Client SHOULD notify its support for CACHE_DIGEST frames by sending the SETTINGS_SENDING_CACHE_DIGEST (0xXXX) SETTINGS parameter.</t>
         <t>The value of the parameter is a bit-field of which the following bits are defined:</t>
         <t>DIGEST_PENDING (0x1): When set it indicates that the client has a digest to send, and the server may choose to wait for a digest in order to make server push decisions.</t>
         <t>Rest of the bits MUST be ignored and MUST be left unset when sending.</t>
         <t>The initial value of the parameter is zero (0x0) meaning that the client has no digest to send the server.</t>
      </section>
      <section anchor="the-settingsacceptcachedigest-settings-parameter">
         <name>The SETTINGS_ACCEPT_CACHE_DIGEST SETTINGS Parameter</name>
         <t>A server can notify its support for CACHE_DIGEST frame by sending the SETTINGS_ACCEPT_CACHE_DIGEST (0x7) SETTINGS parameter. If the server is tempted to making optimizations based on CACHE_DIGEST frames, it SHOULD send the SETTINGS parameter immediately after the connection is established.</t>
         <t>The value of the parameter is a bit-field of which the following bits are defined:</t>
         <t>ACCEPT (0x1): When set, it indicates that the server is willing to make use of a digest of cached responses.</t>
         <t>Rest of the bits MUST be ignored and MUST be left unset when sending.</t>
         <t>The initial value of the parameter is zero (0x0) meaning that the server is not interested in seeing a CACHE_DIGEST frame.</t>
         <t>Some underlying transports allow the server's first flight of application data to reach the client at around the same time when the client sends it's first flight data. When such transport (e.g., TLS 1.3 <xref target="I-D.ietf-tls-tls13"/> in full-handshake mode) is used, a client can postpone sending the CACHE_DIGEST frame until it receives a SETTINGS_ACCEPT_CACHE_DIGEST settings value.</t>
         <t>When the underlying transport does not have such property (e.g., TLS 1.3 in 0-RTT mode), a client can reuse the settings value found in previous connections to that origin <xref target="RFC6454"/> to make assumptions.</t>
      </section>
      <section anchor="iana-considerations">
         <name>IANA Considerations</name>
         <t>This document registers the following entry in the Permanent Message Headers Registry, as per <xref target="RFC3864"/>:</t>
         <t>
            <list style="symbols">
               <t>Header field name: Cache-Digest</t>
               <t>Applicable protocol: http</t>
               <t>Status: experimental</t>
               <t>Author/Change controller: IESG</t>
               <t>Specification document(s): [this document]</t>
            </list>
         </t>
         <t>This document registers the following entry in the HTTP/2 Frame Type Registry, as per <xref target="RFC7540"/>:</t>
         <t>
            <list style="symbols">
               <t>Frame Type: CACHE_DIGEST</t>
               <t>Code: 0xd</t>
               <t>Specification: [this document]</t>
            </list>
         </t>
         <t>This document registers the following entry in the HTTP/2 Settings Registry, as per <xref target="RFC7540"/>:</t>
         <t>
            <list style="symbols">
               <t>Code: 0x7</t>
               <t>Name: SETTINGS_ACCEPT_CACHE_DIGEST</t>
               <t>Initial Value: 0x0</t>
               <t>Reference: [this document]</t>
            </list>
         </t>
      </section>
      <section anchor="security-considerations">
         <name>Security Considerations</name>
         <t>The contents of a User Agent's cache can be used to re-identify or "fingerprint" the user over time, even when other identifiers (e.g., Cookies <xref target="RFC6265"/>) are cleared.</t>
         <t>CACHE_DIGEST allows such cache-based fingerprinting to become passive, since it allows the server to discover the state of the client's cache without any visible change in server behaviour.</t>
         <t>As a result, clients MUST mitigate for this threat when the user attempts to remove identifiers (e.g., "clearing cookies"). This could be achieved in a number of ways; for example: by clearing the cache, by changing one or both of N and P, or by adding new, synthetic entries to the digest to change its contents.</t>
         <t>TODO: discuss how effective the suggested mitigations actually would be.</t>
         <t>Additionally, User Agents SHOULD NOT send CACHE_DIGEST when in "privacy mode."</t>
      </section>
   </middle>
   <back>
      <references anchor="sec-combined-references" title="References">
         <references anchor="sec-normative-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="RFC3986">
               <front>
                  <title>Uniform Resource Identifier (URI): Generic Syntax</title>
                  <author fullname="T. Berners-Lee" initials="T." surname="Berners-Lee"/>
                  <author fullname="R. Fielding" initials="R." surname="Fielding"/>
                  <author fullname="L. Masinter" initials="L." surname="Masinter"/>
                  <date month="January" year="2005"/>
               </front>
               <seriesInfo name="STD" value="66"/>
               <seriesInfo name="RFC" value="3986"/>
               <seriesInfo name="DOI" value="10.17487/RFC3986"/>
            </reference>
            <reference anchor="RFC6234">
               <front>
                  <title>US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)</title>
                  <author fullname="D. Eastlake 3rd" initials="D." surname="Eastlake 3rd"/>
                  <author fullname="T. Hansen" initials="T." surname="Hansen"/>
                  <date month="May" year="2011"/>
               </front>
               <seriesInfo name="RFC" value="6234"/>
               <seriesInfo name="DOI" value="10.17487/RFC6234"/>
            </reference>
            <reference anchor="RFC7230">
               <front>
                  <title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
                  <author fullname="R. Fielding"
                          initials="R."
                          role="editor"
                          surname="Fielding"/>
                  <author fullname="J. Reschke"
                          initials="J."
                          role="editor"
                          surname="Reschke"/>
                  <date month="June" year="2014"/>
               </front>
               <seriesInfo name="RFC" value="7230"/>
               <seriesInfo name="DOI" value="10.17487/RFC7230"/>
            </reference>
            <reference anchor="RFC7232">
               <front>
                  <title>Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests</title>
                  <author fullname="R. Fielding"
                          initials="R."
                          role="editor"
                          surname="Fielding"/>
                  <author fullname="J. Reschke"
                          initials="J."
                          role="editor"
                          surname="Reschke"/>
                  <date month="June" year="2014"/>
               </front>
               <seriesInfo name="RFC" value="7232"/>
               <seriesInfo name="DOI" value="10.17487/RFC7232"/>
            </reference>
            <reference anchor="RFC7234">
               <front>
                  <title>Hypertext Transfer Protocol (HTTP/1.1): Caching</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="2014"/>
               </front>
               <seriesInfo name="RFC" value="7234"/>
               <seriesInfo name="DOI" value="10.17487/RFC7234"/>
            </reference>
            <reference anchor="RFC7540">
               <front>
                  <title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
                  <author fullname="M. Belshe" initials="M." surname="Belshe"/>
                  <author fullname="R. Peon" initials="R." surname="Peon"/>
                  <author fullname="M. Thomson"
                          initials="M."
                          role="editor"
                          surname="Thomson"/>
                  <date month="May" year="2015"/>
               </front>
               <seriesInfo name="RFC" value="7540"/>
               <seriesInfo name="DOI" value="10.17487/RFC7540"/>
            </reference>
            <reference anchor="RFC6454">
               <front>
                  <title>The Web Origin Concept</title>
                  <author fullname="A. Barth" initials="A." surname="Barth"/>
                  <date month="December" year="2011"/>
               </front>
               <seriesInfo name="RFC" value="6454"/>
               <seriesInfo name="DOI" value="10.17487/RFC6454"/>
            </reference>
         </references>
         <references anchor="sec-informative-references" title="Informative References">
            <reference anchor="RFC4648">
               <front>
                  <title>The Base16, Base32, and Base64 Data Encodings</title>
                  <author fullname="S. Josefsson" initials="S." surname="Josefsson"/>
                  <date month="October" year="2006"/>
               </front>
               <seriesInfo name="RFC" value="4648"/>
               <seriesInfo name="DOI" value="10.17487/RFC4648"/>
            </reference>
            <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="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>
            <reference anchor="I-D.ietf-tls-tls13">
               <front>
                  <title>The Transport Layer Security (TLS) Protocol Version 1.3</title>
                  <author fullname="Eric Rescorla" initials="E." surname="Rescorla">
                     <organization>RTFM, Inc.</organization>
                  </author>
                  <date day="20" month="March" year="2018"/>
               </front>
               <seriesInfo name="Internet-Draft" value="draft-ietf-tls-tls13-28"/>
            </reference>
            <reference anchor="Service-Workers"
                       target="https://www.w3.org/TR/2016/WD-service-workers-1-20161011/">
               <front>
                  <title>Service Workers 1</title>
                  <author fullname="Alex Russell" initials="A." surname="Russell"/>
                  <author fullname="Jungkee Song" initials="J." surname="Song"/>
                  <author fullname="Jake Archibald" initials="J." surname="Archibald"/>
                  <author fullname="Marijn Kruisselbrink"
                          initials="M."
                          surname="Kruisselbrink"/>
                  <date month="October" year="2016"/>
               </front>
               <seriesInfo name="W3C Working Draft" value="WD-service-workers-1-20161011"/>
            </reference>
            <reference anchor="Fetch" target="https://fetch.spec.whatwg.org/">
               <front>
                  <title>Fetch Standard</title>
                  <author/>
                  <date year="n.d."/>
               </front>
            </reference>
            <reference anchor="Cuckoo"
                       target="https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf">
               <front>
                  <title>Cuckoo Filter: Practically Better Than Bloom</title>
                  <author/>
                  <date year="n.d."/>
               </front>
            </reference>
            <reference anchor="RFC3864">
               <front>
                  <title>Registration Procedures for Message Header Fields</title>
                  <author fullname="G. Klyne" initials="G." surname="Klyne"/>
                  <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
                  <author fullname="J. Mogul" initials="J." surname="Mogul"/>
                  <date month="September" year="2004"/>
               </front>
               <seriesInfo name="BCP" value="90"/>
               <seriesInfo name="RFC" value="3864"/>
               <seriesInfo name="DOI" value="10.17487/RFC3864"/>
            </reference>
         </references>
      </references>
      <?line 420?>
      <section anchor="encoding-the-cachedigest-frame-as-an-http-header">
         <name>Encoding the CACHE_DIGEST frame as an HTTP Header</name>
         <t>On some web browsers that support Service Workers <xref target="Service-Workers"/> but not Cache Digests (yet), it is possible to achieve the benefit of using Cache Digests by emulating the frame using HTTP Headers.</t>
         <t>For the sake of interoperability with such clients, this appendix defines how a CACHE_DIGEST frame can be encoded as an HTTP header named <spanx style="verb">Cache-Digest</spanx>.</t>
         <t>The definition uses the Augmented Backus-Naur Form (ABNF) notation of <xref target="RFC5234"/> with the list rule extension defined in <xref target="RFC7230" x:fmt="," x:sec="7"/>.</t>
         <figure>
            <sourcecode type="abnf7230">
  Cache-Digest  = 1#digest-entity
  digest-entity = digest-value *(OWS ";" OWS digest-flag)
  digest-value  = &lt;Digest-Value encoded using base64url&gt;
  digest-flag   = token
</sourcecode>
         </figure>
         <t>A Cache-Digest request header is defined as a list construct of cache-digest-entities. Each cache-digest-entity corresponds to a CACHE_DIGEST frame.</t>
         <t>Digest-Value is encoded using base64url <xref target="RFC4648" x:fmt="," x:sec="5"/>. Flags that are set are encoded as digest-flags by their names that are compared case-insensitively.</t>
         <t>Origin is omitted in the header form. The value is implied from the value of the <spanx style="verb">:authority</spanx> pseudo header. Client MUST only send Cache-Digest headers containing digests that belong to the origin specified by the HTTP request.</t>
         <t>The example below contains a digest of one resource and has only the <spanx style="verb">COMPLETE</spanx> flag set.</t>
         <figure>
            <sourcecode type="example">
  Cache-Digest: AfdA; complete
</sourcecode>
         </figure>
         <t>Clients MUST associate Cache-Digest headers to every HTTP request, since Fetch <xref target="Fetch"/> - the HTTP API supported by Service Workers - does not define the order in which the issued requests will be sent to the server nor guarantees that all the requests will be transmitted using a single HTTP/2 connection.</t>
         <t>Also, due to the fact that any header that is supplied to Fetch is required to be end-to-end, there is an ambiguity in what a Cache-Digest header respresents when a request is transmitted through a proxy. The header may represent the cache state of a client or that of a proxy, depending on how the proxy handles the header.</t>
      </section>
      <section anchor="changes">
         <name>Changes</name>
         <section anchor="since-draft-ietf-httpbis-cache-digest-05">
            <name>Since draft-ietf-httpbis-cache-digest-05</name>
            <t>
               <list style="symbols">
                  <t>None yet.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-cache-digest-04">
            <name>Since draft-ietf-httpbis-cache-digest-04</name>
            <t>
               <list style="symbols">
                  <t>Remove ETag from the digest key calculations.</t>
                  <t>Add SETTINGS_ prefix to parameter names.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-cache-digest-03">
            <name>Since draft-ietf-httpbis-cache-digest-03</name>
            <t>
               <list style="symbols">
                  <t>Yoav becomes an author; Mark steps down.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-cache-digest-02">
            <name>Since draft-ietf-httpbis-cache-digest-02</name>
            <t>
               <list style="symbols">
                  <t>Switch to Cuckoo Filter.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-cache-digest-01">
            <name>Since draft-ietf-httpbis-cache-digest-01</name>
            <t>
               <list style="symbols">
                  <t>Added definition of the Cache-Digest header.</t>
                  <t>Introduce ACCEPT_CACHE_DIGEST SETTINGS parameter.</t>
                  <t>Change intended status from Standard to Experimental.</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpbis-cache-digest-00">
            <name>Since draft-ietf-httpbis-cache-digest-00</name>
            <t>
               <list style="symbols">
                  <t>Make the scope of a digest frame explicit and shift to stream 0.</t>
               </list>
            </t>
         </section>
      </section>
      <section anchor="acknowledgements" numbered="false">
         <name>Acknowledgements</name>
         <t>Thanks to Stefan Eissing for his suggestions.</t>
      </section>
   </back>
</rfc>
