Skip to content
Permalink
Browse files

Add cache mode concept and elaborate a bit on caching.

This should fix these issues partially:
* w3c/ServiceWorker#398
* w3c/ServiceWorker#412
  • Loading branch information...
annevk committed Sep 22, 2014
1 parent 7d6d621 commit 99377cd334e7e4e7737c2b2fd521c74a6cf7e01a
Showing with 198 additions and 54 deletions.
  1. +100 −28 Overview.html
  2. +98 −26 Overview.src.html
@@ -7,7 +7,7 @@

<p><a class="logo" href="//www.whatwg.org/"><img alt="WHATWG" height="100" src="//resources.whatwg.org/logo-fetch.svg" width="100"></a>
<h1 id="cors">Fetch</h1>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-15-september-2014">Living Standard — Last Updated 15 September 2014</h2>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-22-september-2014">Living Standard — Last Updated 22 September 2014</h2>

<dl>
<dt>This Version:
@@ -34,7 +34,7 @@ <h2 class="no-num no-toc" id="living-standard-—-last-updated-15-september-2014
<p class="copyright"><a href="//creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="//i.creativecommons.org/p/zero/1.0/80x15.png"></a>
To the extent possible under law, the editor has waived all copyright and
related or neighboring rights to this work. In addition, as of
15 September 2014, the editor has made this specification available
22 September 2014, the editor has made this specification available
under the
<a href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0" rel="license">Open Web Foundation Agreement Version 1.0</a>,
which is available at
@@ -731,6 +731,22 @@ <h4 id="requests"><span class="secno">2.1.4 </span>Requests</h4>
<dfn id="concept-request-use-url-credentials-flag" title="concept-request-use-url-credentials-flag">use URL credentials flag</dfn>.
Unless stated otherwise, it is unset.

<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache mode</dfn>, which is one of
<i title="">default</i>, <i title="">local</i>, and <i title="">skip</i>. Unless stated
otherwise, it is <i title="">default</i>.

<p class="note no-backref">If <a href="#concept-request-header-list" title="concept-request-header-list">header list</a>
contains a <a href="#concept-header" title="concept-header">header</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is one of
`<code title="">If-Modified-Since</code>`,
`<code title="">If-None-Match</code>`,
`<code title="">If-Unmodified-Since</code>`,
`<code title="">If-Match</code>`, and
`<code title="">If-Range</code>`, <span tilte="concept-fetch">fetch</span> will set
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> to <i title="">local</i> if it is
<i title="">default</i>.

<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-manual-redirect-flag" title="concept-request-manual-redirect-flag">manual redirect flag</dfn>. Unless stated
otherwise, it is unset.
@@ -1439,6 +1455,18 @@ <h3 id="http-fetch"><span class="secno">4.2 </span>HTTP fetch</h3>
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is
<i title="">same-origin</i> and the <i title="">CORS flag</i> is unset, and unset otherwise.

<li><p>If <var title="">request</var>'s
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is <i title="">default</i> and
<var title="">request</var>'s <a href="#concept-request-header-list" title="concept-request-header-list">header list</a>
contains a <a href="#concept-header" title="concept-header">header</a>
<span title="concept-header-named">named</span>
`<code title="">If-Modified-Since</code>`,
`<code title="">If-None-Match</code>`,
`<code title="">If-Unmodified-Since</code>`,
`<code title="">If-Match</code>`, or
`<code title="">If-Range</code>`, set <var title="">request</var>'s
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> to <i title="">local</i>.

<li><p>Set <var title="">response</var> to the result of performing an
<a href="#concept-http-network-or-cache-fetch" title="concept-http-network-or-cache-fetch">HTTP network or cache fetch</a>
using <var title="">request</var> with <var title="">credentials flag</var> if set and
@@ -1459,20 +1487,43 @@ <h3 id="http-fetch"><span class="secno">4.2 </span>HTTP fetch</h3>
<a href="#concept-response-status" title="concept-response-status">status</a>:

<dl class="switch">
<dt>304
<dd><p class="XXX">For responses that are a result of a user agent generated conditional request
the user agent must act as if the server gave a <code>200 OK</code> response with the
appropriate content. The user agent must allow a <var title="">request</var>'s
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> to
override automatic cache validation (e.g. `<code>If-None-Match</code>` or
`<code>If-Modified-Since</code>`), in which case <code>304 Not Modified</code> responses
must be passed through.

<dt>301
<dt>302
<dt>303
<dt>307
<dt>308
<dt><code title="">304</code>
<dd>
<ol>
<li><p>If <var title="">request</var>'s
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is not <i title="">default</i>,
do nothing.

<li>
<p>Otherwise, run these subsubsteps:

<ol>
<li><p>If there is no entry in the HTTP cache for <var title="">request</var> and
<var title="">response</var>, return a
<a href="#concept-network-error" title="concept-network-error">network error</a>.
<!-- XXX xref "HTTP cache" -->

<li><p>Update the entry in the HTTP cache for <var title="">request</var> and
<var title="">response</var>, using <var title="">response</var>.
<!-- XXX xref "HTTP cache" -->

<li>
<p>Set <var title="">response</var> to the result of obtaining a
<a href="#concept-response" title="concept-response">response</a> from the HTTP cache using
<var title="">request</var> and <var title="">response</var>.
<!-- XXX xref "HTTP cache" -->

<p class="note no-backref">This changes <var title="">response</var> entirely,
including its <a href="#concept-response-status" title="concept-response-status">status</a> which is most
likely <code title="">200</code> now.
</ol>
</ol>

<dt><code title="">301</code>
<dt><code title="">302</code>
<dt><code title="">303</code>
<dt><code title="">307</code>
<dt><code title="">308</code>
<dd>
<ol>
<li>
@@ -1537,7 +1588,7 @@ <h3 id="http-fetch"><span class="secno">4.2 </span>HTTP fetch</h3>
</ol>
</ol>

<dt>401
<dt><code title="">401</code>
<dd>
<ol>
<li><p>If <var title="">request</var>'s <a href="#authentication-flag">authentication flag</a> is unset or the
@@ -1567,7 +1618,7 @@ <h3 id="http-fetch"><span class="secno">4.2 </span>HTTP fetch</h3>
<!-- cannot invoke >HTTP network or cache fetch< as that would not come back here -->
</ol>

<dt>407
<dt><code title="">407</code>
<dd>
<ol>
<li class="XXX"><p>Needs testing: multiple `<code>Proxy-Authenticate</code>` headers,
@@ -1691,8 +1742,32 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">4.3 </span>HTTP network
<var title="">HTTPRequest</var>'s
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a>.

<li><p>Let <var title="">response</var> be null.

<li>
<p>Modify <var title="">HTTPRequest</var>'s
<p>If <var title="">request</var>'s
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is not <i title="">skip</i> and
there is a <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
<var title="">request</var> run these substeps:
<!-- XXX xref "HTTP cache" -->

<ol>
<li><p>If the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
<var title="">request</var> does not require revalidation, set <var title="">response</var>
to that <a href="#concept-response" title="concept-response">response</a>.
<!-- XXX xref "HTTP cache", "revalidation" -->

<li><p>Otherwise, if the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache
for <var title="">request</var> does require revalidation, and <var title="">request</var>'s
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is <i title="">default</i>,
modify <var title="">HTTPRequest</var>'s
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> with revalidation
<a href="#concept-header" title="concept-header">headers</a>.
<!-- XXX xref "HTTP cache", "revalidation" -->
</ol>

<li>
<p>If <var title="">response</var> is null, modify <var title="">HTTPRequest</var>'s
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> per HTTP.

<p class="note no-backref">It would be great if we could make this more normative
@@ -1709,15 +1784,12 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">4.3 </span>HTTP network
point. <span class="note">See <a href="#http-header-layer-division">HTTP header layer division</a>.</span>

<li>
<p class="XXX"><a href="https://github.com/slightlyoff/ServiceWorker/issues/398">Handle caches</a>.

<li>
<p>Let <var title="">response</var> be the result of making an HTTP request, using
<var title="">HTTPRequest</var>, following the requirements from HTTP as appropriate, and
waiting until either all the <a href="#concept-header" title="concept-header">headers</a> are transmitted
or a <a href="#concept-network-error" title="concept-network-error">network error</a> was returned. If a
<a href="#concept-network-error" title="concept-network-error">network error</a> was returned due to
<a href="#concept-fetch" title="concept-fetch">fetch</a> being
<p>If <var title="">response</var> is null, set <var title="">response</var> to the result of
making an HTTP request, using <var title="">HTTPRequest</var>, following the requirements
from HTTP, and waiting until either all the <a href="#concept-header" title="concept-header">headers</a>
are transmitted or a <a href="#concept-network-error" title="concept-network-error">network error</a> was
returned. If a <a href="#concept-network-error" title="concept-network-error">network error</a> was returned due
to <a href="#concept-fetch" title="concept-fetch">fetch</a> being
<a href="#concept-fetch-terminate" title="concept-fetch-terminate">terminated</a> with reason
<var title="">reason</var>, set <var title="">response</var>'s
<a href="#concept-response-termination-reason" title="concept-response-termination-reason">termination reason</a> to
@@ -687,6 +687,22 @@ <h4>Requests</h4>
<dfn title=concept-request-use-url-credentials-flag>use URL credentials flag</dfn>.
Unless stated otherwise, it is unset.

<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-cache-mode>cache mode</dfn>, which is one of
<i title>default</i>, <i title>local</i>, and <i title>skip</i>. Unless stated
otherwise, it is <i title>default</i>.

<p class="note no-backref">If <span title=concept-request-header-list>header list</span>
contains a <span title=concept-header>header</span> whose
<span title=concept-header-name>name</span> is one of
`<code title>If-Modified-Since</code>`,
`<code title>If-None-Match</code>`,
`<code title>If-Unmodified-Since</code>`,
`<code title>If-Match</code>`, and
`<code title>If-Range</code>`, <span tilte=concept-fetch>fetch</span> will set
<span title=concept-request-cache-mode>cache mode</span> to <i title>local</i> if it is
<i title>default</i>.

<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-manual-redirect-flag>manual redirect flag</dfn>. Unless stated
otherwise, it is unset.
@@ -1395,6 +1411,18 @@ <h3>HTTP fetch</h3>
<span title=concept-request-credentials-mode>credentials mode</span> is
<i title>same-origin</i> and the <i title>CORS flag</i> is unset, and unset otherwise.

<li><p>If <var title>request</var>'s
<span title=concept-request-cache-mode>cache mode</span> is <i title>default</i> and
<var title>request</var>'s <span title=concept-request-header-list>header list</span>
contains a <span title=concept-header>header</span>
<span title=concept-header-named>named</span>
`<code title>If-Modified-Since</code>`,
`<code title>If-None-Match</code>`,
`<code title>If-Unmodified-Since</code>`,
`<code title>If-Match</code>`, or
`<code title>If-Range</code>`, set <var title>request</var>'s
<span title=concept-request-cache-mode>cache mode</span> to <i title>local</i>.

<li><p>Set <var title>response</var> to the result of performing an
<span title=concept-http-network-or-cache-fetch>HTTP network or cache fetch</span>
using <var title>request</var> with <var title>credentials flag</var> if set and
@@ -1415,20 +1443,43 @@ <h3>HTTP fetch</h3>
<span title=concept-response-status>status</span>:

<dl class=switch>
<dt>304
<dd><p class=XXX>For responses that are a result of a user agent generated conditional request
the user agent must act as if the server gave a <code>200 OK</code> response with the
appropriate content. The user agent must allow a <var title>request</var>'s
<span title=concept-request-header-list>header list</span> to
override automatic cache validation (e.g. `<code>If-None-Match</code>` or
`<code>If-Modified-Since</code>`), in which case <code>304 Not Modified</code> responses
must be passed through.

<dt>301
<dt>302
<dt>303
<dt>307
<dt>308
<dt><code title>304</code>
<dd>
<ol>
<li><p>If <var title>request</var>'s
<span title=concept-request-cache-mode>cache mode</span> is not <i title>default</i>,
do nothing.

<li>
<p>Otherwise, run these subsubsteps:

<ol>
<li><p>If there is no entry in the HTTP cache for <var title>request</var> and
<var title>response</var>, return a
<span title=concept-network-error>network error</span>.
<!-- XXX xref "HTTP cache" -->

<li><p>Update the entry in the HTTP cache for <var title>request</var> and
<var title>response</var>, using <var title>response</var>.
<!-- XXX xref "HTTP cache" -->

<li>
<p>Set <var title>response</var> to the result of obtaining a
<span title=concept-response>response</span> from the HTTP cache using
<var title>request</var> and <var title>response</var>.
<!-- XXX xref "HTTP cache" -->

<p class="note no-backref">This changes <var title>response</var> entirely,
including its <span title=concept-response-status>status</span> which is most
likely <code title>200</code> now.
</ol>
</ol>

<dt><code title>301</code>
<dt><code title>302</code>
<dt><code title>303</code>
<dt><code title>307</code>
<dt><code title>308</code>
<dd>
<ol>
<li>
@@ -1493,7 +1544,7 @@ <h3>HTTP fetch</h3>
</ol>
</ol>

<dt>401
<dt><code title>401</code>
<dd>
<ol>
<li><p>If <var title>request</var>'s <span>authentication flag</span> is unset or the
@@ -1523,7 +1574,7 @@ <h3>HTTP fetch</h3>
<!-- cannot invoke >HTTP network or cache fetch< as that would not come back here -->
</ol>

<dt>407
<dt><code title>407</code>
<dd>
<ol>
<li class=XXX><p>Needs testing: multiple `<code>Proxy-Authenticate</code>` headers,
@@ -1647,8 +1698,32 @@ <h3>HTTP network or cache fetch</h3>
<var title>HTTPRequest</var>'s
<span title=concept-request-credentials-mode>credentials mode</span>.

<li><p>Let <var title>response</var> be null.

<li>
<p>Modify <var title>HTTPRequest</var>'s
<p>If <var title>request</var>'s
<span title=concept-request-cache-mode>cache mode</span> is not <i title>skip</i> and
there is a <span title=concept-response>response</span> in the HTTP cache for
<var title>request</var> run these substeps:
<!-- XXX xref "HTTP cache" -->

<ol>
<li><p>If the <span title=concept-response>response</span> in the HTTP cache for
<var title>request</var> does not require revalidation, set <var title>response</var>
to that <span title=concept-response>response</span>.
<!-- XXX xref "HTTP cache", "revalidation" -->

<li><p>Otherwise, if the <span title=concept-response>response</span> in the HTTP cache
for <var title>request</var> does require revalidation, and <var title>request</var>'s
<span title=concept-request-cache-mode>cache mode</span> is <i title>default</i>,
modify <var title>HTTPRequest</var>'s
<span title=concept-request-header-list>header list</span> with revalidation
<span title=concept-header>headers</span>.
<!-- XXX xref "HTTP cache", "revalidation" -->
</ol>

<li>
<p>If <var title>response</var> is null, modify <var title>HTTPRequest</var>'s
<span title=concept-request-header-list>header list</span> per HTTP.

<p class="note no-backref">It would be great if we could make this more normative
@@ -1665,15 +1740,12 @@ <h3>HTTP network or cache fetch</h3>
point. <span class=note>See <span>HTTP header layer division</span>.</span>

<li>
<p class=XXX><a href=https://github.com/slightlyoff/ServiceWorker/issues/398>Handle caches</a>.

<li>
<p>Let <var title>response</var> be the result of making an HTTP request, using
<var title>HTTPRequest</var>, following the requirements from HTTP as appropriate, and
waiting until either all the <span title=concept-header>headers</span> are transmitted
or a <span title=concept-network-error>network error</span> was returned. If a
<span title=concept-network-error>network error</span> was returned due to
<span title=concept-fetch>fetch</span> being
<p>If <var title>response</var> is null, set <var title>response</var> to the result of
making an HTTP request, using <var title>HTTPRequest</var>, following the requirements
from HTTP, and waiting until either all the <span title=concept-header>headers</span>
are transmitted or a <span title=concept-network-error>network error</span> was
returned. If a <span title=concept-network-error>network error</span> was returned due
to <span title=concept-fetch>fetch</span> being
<span title=concept-fetch-terminate>terminated</span> with reason
<var title>reason</var>, set <var title>response</var>'s
<span title=concept-response-termination-reason>termination reason</span> to

0 comments on commit 99377cd

Please sign in to comment.
You can’t perform that action at this time.