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

Lines changed: 35 additions & 14 deletions
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">Fetchh1>
10-
<h2 class="no-num no-toc" id="living-standard-—-last-updated-5-may-2016">Living Standard — Last Updated 5 May 2016h2>
10+
<h2 class="no-num no-toc" id="living-standard-—-last-updated-18-may-2016">Living Standard — Last Updated 18 May 2016h2>
1111

1212
<dl>
1313
<dt>Participate:
@@ -975,10 +975,10 @@

3.1.5 Requests

975975
Unless stated otherwise, it is unset.
976976

977977
<p>A <a href="#concept-request" title="concept-request">requesta> has an associated
978-
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache modedfn>, which is
979-
"<code title="">defaultcode>", "<code title="">no-storecode>", "<code title="">reloadcode>",
980-
"<code title="">no-cachecode>", or "<code title="">force-cachecode>". Unless stated otherwise, it is
981-
"<code title="">defaultcode>".
978+
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache modedfn>, which is "<code title="">defaultcode>",
979+
"<code title="">no-storecode>", "<code title="">reloadcode>", "<code title="">no-cachecode>",
980+
"<code title="">force-cachecode>", or "<code title="">only-if-cachedcode>". Unless stated otherwise,
981+
it is "<code title="">defaultcode>".
982982

983983
<div class="note no-backref">
984984
<dl>
@@ -1001,8 +1001,14 @@

3.1.5 Requests

10011001

10021002
<dt>"<code title="">force-cachecode>"
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-cachedcode>"
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">requesta>'s <span tilte="concept-request-mode">modespan> is
1011+
"<code title="">same-origincode>".)
10061012
dl>
10071013

10081014
<p>If <a href="#concept-request-header-list" title="concept-request-header-list">header lista> contains a
@@ -3257,8 +3263,9 @@

5.5 HTTP-network

32573263
<ol>
32583264
<li>
32593265
<p>If <var>httpRequestvar>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache modea> is
3260-
"<code title="">force-cachecode>", set <var>responsevar> to the
3261-
<a href="#concept-response" title="concept-response">responsea> in the HTTP cache for <var>httpRequestvar>.
3266+
"<code title="">force-cachecode>" or "<code title="">only-if-cachedcode>", then set
3267+
<var>responsevar> to the <a href="#concept-response" title="concept-response">responsea> in the HTTP cache for
3268+
<var>httpRequestvar>.
32623269

32633270
<p class="note">As mandated by HTTP, this still takes the `<code title="http-vary">Varycode>`
32643271
<a href="#concept-header" title="concept-header">headera> into account.
@@ -3289,9 +3296,18 @@

5.5 HTTP-network

32893296
<a href="#concept-header" title="concept-header">headersa>.
32903297
32913298

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

32963312
<li>
32973313
<p>If <var>responsevar>'s <a href="#concept-status" title="status">statusa> is <code>304code> and
@@ -4446,7 +4462,7 @@

6.3 Request class

44464462
enum <dfn id="requestdestination">RequestDestinationdfn> { "", "document", "embed", "font", "image", "manifest", "media", "object", "report", "script", "serviceworker", "sharedworker", "style", "worker", "xslt" };
44474463
enum <dfn id="requestmode">RequestModedfn> { "navigate", "same-origin", "no-cors", "cors" };
44484464
enum <dfn id="requestcredentials">RequestCredentialsdfn> { "omit", "same-origin", "include" };
4449-
enum <dfn id="requestcache">RequestCachedfn> { "default", "no-store", "reload", "no-cache", "force-cache" };
4465+
enum <dfn id="requestcache">RequestCachedfn> { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
44504466
enum <dfn id="requestredirect">RequestRedirectdfn> { "follow", "error", "manual" };pre>
44514467

44524468
<p class="note no-backref">"<code>serviceworkercode>" is omitted from
@@ -4655,6 +4671,11 @@

6.3 Request class

46554671
<var>requestvar>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache modea> to
46564672
it.
46574673

4674+
<li><p>If <var>requestvar>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache modea> is
4675+
"<code title="">only-if-cachedcode>" and <var>requestvar>'s
4676+
<a href="#concept-request-mode" title="concept-request-mode">modea> is <em>notem> "<code title="">same-origincode>", then
4677+
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throwa> a <code title="">TypeErrorcode>.
4678+
46584679
<li><p>If <var>initvar>'s <code title="">redirectcode> member is present, set
46594680
<var>requestvar>'s <a href="#concept-request-redirect-mode" title="concept-request-redirect-mode">redirect modea>
46604681
to it.
@@ -5453,7 +5474,7 @@

References

54535474
<dd>(Non-normative) <cite><a href="https://tools.ietf.org/html/rfc6454">The Web Origin Concepta>cite>, Adam Barth. IETF.
54545475

54555476
<dt id="refsREFERRER">[REFERRER]
5456-
<dd><cite><a href="https://w3c.github.io/webappsec-referrer-policy/">Referrer Policya>cite>, Jochen Eisinger and Mike West. W3C.
5477+
<dd><cite><a href="https://w3c.github.io/webappsec-referrer-policy/">Referrer Policya>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 Levelsa>cite>, Scott Bradner. IETF.

Overview.src.html

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@

Requests

903903
Unless stated otherwise, it is unset.
904904

905905
<p>A <span title=concept-request>requestspan> has an associated
906-
<dfn title=concept-request-cache-mode>cache modedfn>, which is
907-
"<code title>defaultcode>", "<code title>no-storecode>", "<code title>reloadcode>",
908-
"<code title>no-cachecode>", or "<code title>force-cachecode>". Unless stated otherwise, it is
909-
"<code title>defaultcode>".
906+
<dfn title=concept-request-cache-mode>cache modedfn>, which is "<code title>defaultcode>",
907+
"<code title>no-storecode>", "<code title>reloadcode>", "<code title>no-cachecode>",
908+
"<code title>force-cachecode>", or "<code title>only-if-cachedcode>". Unless stated otherwise,
909+
it is "<code title>defaultcode>".
910910

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

Requests

929929

930930
<dt>"<code title>force-cachecode>"
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-cachedcode>"
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>requestspan>'s <span tilte=concept-request-mode>modespan> is
939+
"<code title>same-origincode>".)
934940
dl>
935941

936942
<p>If <span title=concept-request-header-list>header listspan> contains a
@@ -3185,8 +3191,9 @@

HTTP-network-or-cache fetch

31853191
<ol>
31863192
<li>
31873193
<p>If <var>httpRequestvar>'s <span title=concept-request-cache-mode>cache modespan> is
3188-
"<code title>force-cachecode>", set <var>responsevar> to the
3189-
<span title=concept-response>responsespan> in the HTTP cache for <var>httpRequestvar>.
3194+
"<code title>force-cachecode>" or "<code title>only-if-cachedcode>", then set
3195+
<var>responsevar> to the <span title=concept-response>responsespan> in the HTTP cache for
3196+
<var>httpRequestvar>.
31903197

31913198
<p class="note">As mandated by HTTP, this still takes the `<code title=http-vary>Varycode>`
31923199
<span title=concept-header>headerspan> into account.
@@ -3217,9 +3224,18 @@

HTTP-network-or-cache fetch

32173224
<span title=concept-header>headersspan>.
32183225
32193226

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

32243240
<li>
32253241
<p>If <var>responsevar>'s <span title=status>statusspan> is <code>304code> and
@@ -4374,7 +4390,7 @@

Request class

43744390
enum <dfn>RequestDestinationdfn> { "", "document", "embed", "font", "image", "manifest", "media", "object", "report", "script", "serviceworker", "sharedworker", "style", "worker", "xslt" };
43754391
enum <dfn>RequestModedfn> { "navigate", "same-origin", "no-cors", "cors" };
43764392
enum <dfn>RequestCredentialsdfn> { "omit", "same-origin", "include" };
4377-
enum <dfn>RequestCachedfn> { "default", "no-store", "reload", "no-cache", "force-cache" };
4393+
enum <dfn>RequestCachedfn> { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
43784394
enum <dfn>RequestRedirectdfn> { "follow", "error", "manual" };pre>
43794395

43804396
<p class="note no-backref">"<code>serviceworkercode>" is omitted from
@@ -4583,6 +4599,11 @@

Request class

45834599
<var>requestvar>'s <span title=concept-request-cache-mode>cache modespan> to
45844600
it.
45854601

4602+
<li><p>If <var>requestvar>'s <span title=concept-request-cache-mode>cache modespan> is
4603+
"<code title>only-if-cachedcode>" and <var>requestvar>'s
4604+
<span title=concept-request-mode>modespan> is <em>notem> "<code title>same-origincode>", then
4605+
<span data-anolis-spec=webidl>throwspan> a <code title>TypeErrorcode>.
4606+
45864607
<li><p>If <var>initvar>'s <code title>redirectcode> member is present, set
45874608
<var>requestvar>'s <span title=concept-request-redirect-mode>redirect modespan>
45884609
to it.

0 commit comments

Comments
 (0)