Skip to content

Commit fef8c9a

Browse files
committed
Add "only-if-cached" cache mode back
Fixes #159. The difference with the previous attempt, see 886255d for its revert, is that it now has a “same-origin” mode restriction (enforced through the Fetch API). (Also closes #305 as the reference database has been updated.)
1 parent f080d2f commit fef8c9a

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

Overview.html

+35-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<p><a class="logo" href="https://whatwg.org/"><img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-fetch.svg" width="100"></a>
99
<h1 id="cors">Fetch</h1>
10-
<h2 class="no-num no-toc" id="living-standard-—-last-updated-5-may-2016">Living Standard — Last Updated 5 May 2016</h2>
10+
<h2 class="no-num no-toc" id="living-standard-—-last-updated-18-may-2016">Living Standard — Last Updated 18 May 2016</h2>
1111

1212
<dl>
1313
<dt>Participate:
@@ -975,10 +975,10 @@ <h4 id="requests"><span class="secno">3.1.5 </span>Requests</h4>
975975
Unless stated otherwise, it is unset.
976976

977977
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
978-
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache mode</dfn>, which is
979-
"<code title="">default</code>", "<code title="">no-store</code>", "<code title="">reload</code>",
980-
"<code title="">no-cache</code>", or "<code title="">force-cache</code>". Unless stated otherwise, it is
981-
"<code title="">default</code>".
978+
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache mode</dfn>, which is "<code title="">default</code>",
979+
"<code title="">no-store</code>", "<code title="">reload</code>", "<code title="">no-cache</code>",
980+
"<code title="">force-cache</code>", or "<code title="">only-if-cached</code>". Unless stated otherwise,
981+
it is "<code title="">default</code>".
982982

983983
<div class="note no-backref">
984984
<dl>
@@ -1001,8 +1001,14 @@ <h4 id="requests"><span class="secno">3.1.5 </span>Requests</h4>
10011001

10021002
<dt>"<code title="">force-cache</code>"
10031003
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
1004-
staleness. If there was no response, it creates a normal request updates the HTTP cache with the
1005-
response.
1004+
staleness. If there was no response, it creates a normal request and updates the HTTP cache with
1005+
the response.
1006+
1007+
<dt>"<code title="">only-if-cached</code>"
1008+
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
1009+
staleness. If there was no response, it returns a network error. (Can only be used when
1010+
<a href="#concept-request" title="concept-request">request</a>'s <span tilte="concept-request-mode">mode</span> is
1011+
"<code title="">same-origin</code>".)
10061012
</dl>
10071013

10081014
<p>If <a href="#concept-request-header-list" title="concept-request-header-list">header list</a> contains a
@@ -3257,8 +3263,9 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.5 </span>HTTP-network
32573263
<ol>
32583264
<li>
32593265
<p>If <var>httpRequest</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
3260-
"<code title="">force-cache</code>", set <var>response</var> to the
3261-
<a href="#concept-response" title="concept-response">response</a> in the HTTP cache for <var>httpRequest</var>.
3266+
"<code title="">force-cache</code>" or "<code title="">only-if-cached</code>", then set
3267+
<var>response</var> to the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
3268+
<var>httpRequest</var>.
32623269

32633270
<p class="note">As mandated by HTTP, this still takes the `<code title="http-vary">Vary</code>`
32643271
<a href="#concept-header" title="concept-header">header</a> into account.
@@ -3289,9 +3296,18 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.5 </span>HTTP-network
32893296
<a href="#concept-header" title="concept-header">headers</a>.
32903297
<!-- XXX xref partial, modify, resume headers -->
32913298

3292-
<li><p>If <var>response</var> is null, set <var>response</var> to the result of making an
3293-
<a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using <var>httpRequest</var> with
3294-
the <i title="">credentials flag</i> set if set.
3299+
<li>
3300+
<p>If <var>response</var> is null, run these substeps:
3301+
3302+
<ol>
3303+
<li><p>If <var>httpRequest</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
3304+
"<code title="">only-if-cached</code>", then return a
3305+
<a href="#concept-network-error" title="concept-network-error">network error</a>.
3306+
3307+
<li><p>Set <var>response</var> to the result of making an
3308+
<a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using <var>httpRequest</var>
3309+
with the <i title="">credentials flag</i> set if set.
3310+
</ol>
32953311

32963312
<li>
32973313
<p>If <var>response</var>'s <a href="#concept-status" title="status">status</a> is <code>304</code> and
@@ -4446,7 +4462,7 @@ <h3 id="request-class"><span class="secno">6.3 </span>Request class</h3>
44464462
enum <dfn id="requestdestination">RequestDestination</dfn> { "", "document", "embed", "font", "image", "manifest", "media", "object", "report", "script", "serviceworker", "sharedworker", "style", "worker", "xslt" };
44474463
enum <dfn id="requestmode">RequestMode</dfn> { "navigate", "same-origin", "no-cors", "cors" };
44484464
enum <dfn id="requestcredentials">RequestCredentials</dfn> { "omit", "same-origin", "include" };
4449-
enum <dfn id="requestcache">RequestCache</dfn> { "default", "no-store", "reload", "no-cache", "force-cache" };
4465+
enum <dfn id="requestcache">RequestCache</dfn> { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
44504466
enum <dfn id="requestredirect">RequestRedirect</dfn> { "follow", "error", "manual" };</pre>
44514467

44524468
<p class="note no-backref">"<code>serviceworker</code>" is omitted from
@@ -4655,6 +4671,11 @@ <h3 id="request-class"><span class="secno">6.3 </span>Request class</h3>
46554671
<var>request</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> to
46564672
it.
46574673

4674+
<li><p>If <var>request</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
4675+
"<code title="">only-if-cached</code>" and <var>request</var>'s
4676+
<a href="#concept-request-mode" title="concept-request-mode">mode</a> is <em>not</em> "<code title="">same-origin</code>", then
4677+
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.
4678+
46584679
<li><p>If <var>init</var>'s <code title="">redirect</code> member is present, set
46594680
<var>request</var>'s <a href="#concept-request-redirect-mode" title="concept-request-redirect-mode">redirect mode</a>
46604681
to it.
@@ -5453,7 +5474,7 @@ <h2 class="no-num" id="references">References</h2>
54535474
<dd>(Non-normative) <cite><a href="https://tools.ietf.org/html/rfc6454">The Web Origin Concept</a></cite>, Adam Barth. IETF.
54545475

54555476
<dt id="refsREFERRER">[REFERRER]
5456-
<dd><cite><a href="https://w3c.github.io/webappsec-referrer-policy/">Referrer Policy</a></cite>, Jochen Eisinger and Mike West. W3C.
5477+
<dd><cite><a href="https://w3c.github.io/webappsec-referrer-policy/">Referrer Policy</a></cite>, Jochen Eisinger and Emily Stark. W3C.
54575478

54585479
<dt id="refsRFC2119">[RFC2119]
54595480
<dd><cite><a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a></cite>, Scott Bradner. IETF.

Overview.src.html

+33-12
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ <h4>Requests</h4>
903903
Unless stated otherwise, it is unset.
904904

905905
<p>A <span title=concept-request>request</span> has an associated
906-
<dfn title=concept-request-cache-mode>cache mode</dfn>, which is
907-
"<code title>default</code>", "<code title>no-store</code>", "<code title>reload</code>",
908-
"<code title>no-cache</code>", or "<code title>force-cache</code>". Unless stated otherwise, it is
909-
"<code title>default</code>".
906+
<dfn title=concept-request-cache-mode>cache mode</dfn>, which is "<code title>default</code>",
907+
"<code title>no-store</code>", "<code title>reload</code>", "<code title>no-cache</code>",
908+
"<code title>force-cache</code>", or "<code title>only-if-cached</code>". Unless stated otherwise,
909+
it is "<code title>default</code>".
910910

911911
<div class="note no-backref">
912912
<dl>
@@ -929,8 +929,14 @@ <h4>Requests</h4>
929929

930930
<dt>"<code title>force-cache</code>"
931931
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
932-
staleness. If there was no response, it creates a normal request updates the HTTP cache with the
933-
response.
932+
staleness. If there was no response, it creates a normal request and updates the HTTP cache with
933+
the response.
934+
935+
<dt>"<code title>only-if-cached</code>"
936+
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
937+
staleness. If there was no response, it returns a network error. (Can only be used when
938+
<span title=concept-request>request</span>'s <span tilte=concept-request-mode>mode</span> is
939+
"<code title>same-origin</code>".)
934940
</dl>
935941

936942
<p>If <span title=concept-request-header-list>header list</span> contains a
@@ -3185,8 +3191,9 @@ <h3>HTTP-network-or-cache fetch</h3>
31853191
<ol>
31863192
<li>
31873193
<p>If <var>httpRequest</var>'s <span title=concept-request-cache-mode>cache mode</span> is
3188-
"<code title>force-cache</code>", set <var>response</var> to the
3189-
<span title=concept-response>response</span> in the HTTP cache for <var>httpRequest</var>.
3194+
"<code title>force-cache</code>" or "<code title>only-if-cached</code>", then set
3195+
<var>response</var> to the <span title=concept-response>response</span> in the HTTP cache for
3196+
<var>httpRequest</var>.
31903197

31913198
<p class="note">As mandated by HTTP, this still takes the `<code title=http-vary>Vary</code>`
31923199
<span title=concept-header>header</span> into account.
@@ -3217,9 +3224,18 @@ <h3>HTTP-network-or-cache fetch</h3>
32173224
<span title=concept-header>headers</span>.
32183225
<!-- XXX xref partial, modify, resume headers -->
32193226

3220-
<li><p>If <var>response</var> is null, set <var>response</var> to the result of making an
3221-
<span title=concept-http-network-fetch>HTTP-network fetch</span> using <var>httpRequest</var> with
3222-
the <i title>credentials flag</i> set if set.
3227+
<li>
3228+
<p>If <var>response</var> is null, run these substeps:
3229+
3230+
<ol>
3231+
<li><p>If <var>httpRequest</var>'s <span title=concept-request-cache-mode>cache mode</span> is
3232+
"<code title>only-if-cached</code>", then return a
3233+
<span title=concept-network-error>network error</span>.
3234+
3235+
<li><p>Set <var>response</var> to the result of making an
3236+
<span title=concept-http-network-fetch>HTTP-network fetch</span> using <var>httpRequest</var>
3237+
with the <i title>credentials flag</i> set if set.
3238+
</ol>
32233239

32243240
<li>
32253241
<p>If <var>response</var>'s <span title=status>status</span> is <code>304</code> and
@@ -4374,7 +4390,7 @@ <h3>Request class</h3>
43744390
enum <dfn>RequestDestination</dfn> { "", "document", "embed", "font", "image", "manifest", "media", "object", "report", "script", "serviceworker", "sharedworker", "style", "worker", "xslt" };
43754391
enum <dfn>RequestMode</dfn> { "navigate", "same-origin", "no-cors", "cors" };
43764392
enum <dfn>RequestCredentials</dfn> { "omit", "same-origin", "include" };
4377-
enum <dfn>RequestCache</dfn> { "default", "no-store", "reload", "no-cache", "force-cache" };
4393+
enum <dfn>RequestCache</dfn> { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
43784394
enum <dfn>RequestRedirect</dfn> { "follow", "error", "manual" };</pre>
43794395

43804396
<p class="note no-backref">"<code>serviceworker</code>" is omitted from
@@ -4583,6 +4599,11 @@ <h3>Request class</h3>
45834599
<var>request</var>'s <span title=concept-request-cache-mode>cache mode</span> to
45844600
it.
45854601

4602+
<li><p>If <var>request</var>'s <span title=concept-request-cache-mode>cache mode</span> is
4603+
"<code title>only-if-cached</code>" and <var>request</var>'s
4604+
<span title=concept-request-mode>mode</span> is <em>not</em> "<code title>same-origin</code>", then
4605+
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.
4606+
45864607
<li><p>If <var>init</var>'s <code title>redirect</code> member is present, set
45874608
<var>request</var>'s <span title=concept-request-redirect-mode>redirect mode</span>
45884609
to it.

0 commit comments

Comments
 (0)