Skip to content

Commit

Permalink
Add "only-if-cached" cache mode back
Browse files Browse the repository at this point in the history
Fixes #159. The difference with the previous attempt is that it now has
a “same-origin” mode restriction (enforced through the Fetch API).
  • Loading branch information
annevk committed May 4, 2016
1 parent 3ac0156 commit c721ac6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
45 changes: 33 additions & 12 deletions Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,10 @@ <h4 id="requests"><span class="secno">3.1.5 </span>Requests</h4>
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
"<code title="">default</code>", "<code title="">no-store</code>", "<code title="">reload</code>",
"<code title="">no-cache</code>", or "<code title="">force-cache</code>". Unless stated otherwise, it is
"<code title="">default</code>".
<dfn id="concept-request-cache-mode" title="concept-request-cache-mode">cache mode</dfn>, which is "<code title="">default</code>",
"<code title="">no-store</code>", "<code title="">reload</code>", "<code title="">no-cache</code>",
"<code title="">force-cache</code>", or "<code title="">only-if-cached</code>". Unless stated otherwise,
it is "<code title="">default</code>".

<div class="note no-backref">
<dl>
Expand All @@ -990,8 +990,14 @@ <h4 id="requests"><span class="secno">3.1.5 </span>Requests</h4>

<dt>"<code title="">force-cache</code>"
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it creates a normal request updates the HTTP cache with the
response.
staleness. If there was no response, it creates a normal request and updates the HTTP cache with
the response.

<dt>"<code title="">only-if-cached</code>"
<dd>Fetches uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it returns a network error. (Can only be used when
<a href="#concept-request" title="concept-request">request</a>'s <span tilte="concept-request-mode">mode</span> is
"<code title="">same-origin</code>".)
</dl>

<p>If <a href="#concept-request-header-list" title="concept-request-header-list">header list</a> contains a
Expand Down Expand Up @@ -3067,8 +3073,9 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.5 </span>HTTP-network
<ol>
<li>
<p>If <var>httpRequest</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
"<code title="">force-cache</code>", set <var>response</var> to the
<a href="#concept-response" title="concept-response">response</a> in the HTTP cache for <var>httpRequest</var>.
"<code title="">force-cache</code>" or "<code title="">only-if-cached</code>", then set
<var>response</var> to the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
<var>httpRequest</var>.

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

<li><p>If <var>response</var> is null, set <var>response</var> to the result of making an
<a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using <var>httpRequest</var> with
the <i title="">credentials flag</i> set if set.
<li>
<p>If <var>response</var> is null, run these substeps:

<ol>
<li><p>If <var>httpRequest</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
"<code title="">only-if-cached</code>", then return a
<a href="#concept-network-error" title="concept-network-error">network error</a>.

<li><p>Set <var>response</var> to the result of making an
<a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using <var>httpRequest</var>
with the <i title="">credentials flag</i> set if set.
</ol>

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

<p class="note no-backref">"<code>serviceworker</code>" is omitted from
Expand Down Expand Up @@ -4465,6 +4481,11 @@ <h3 id="request-class"><span class="secno">6.3 </span>Request class</h3>
<var>request</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> to
it.

<li><p>If <var>request</var>'s <a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
"<code title="">only-if-cached</code>" and <var>request</var>'s
<a href="#concept-request-mode" title="concept-request-mode">mode</a> is <em>not</em> "<code title="">same-origin</code>", then
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.

<li><p>If <var>init</var>'s <code title="">redirect</code> member is present, set
<var>request</var>'s <a href="#concept-request-redirect-mode" title="concept-request-redirect-mode">redirect mode</a>
to it.
Expand Down
45 changes: 33 additions & 12 deletions Overview.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,10 @@ <h4>Requests</h4>
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
"<code title>default</code>", "<code title>no-store</code>", "<code title>reload</code>",
"<code title>no-cache</code>", or "<code title>force-cache</code>". Unless stated otherwise, it is
"<code title>default</code>".
<dfn title=concept-request-cache-mode>cache mode</dfn>, which is "<code title>default</code>",
"<code title>no-store</code>", "<code title>reload</code>", "<code title>no-cache</code>",
"<code title>force-cache</code>", or "<code title>only-if-cached</code>". Unless stated otherwise,
it is "<code title>default</code>".

<div class="note no-backref">
<dl>
Expand All @@ -920,8 +920,14 @@ <h4>Requests</h4>

<dt>"<code title>force-cache</code>"
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it creates a normal request updates the HTTP cache with the
response.
staleness. If there was no response, it creates a normal request and updates the HTTP cache with
the response.

<dt>"<code title>only-if-cached</code>"
<dd>Fetches uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it returns a network error. (Can only be used when
<span title=concept-request>request</span>'s <span tilte=concept-request-mode>mode</span> is
"<code title>same-origin</code>".)
</dl>

<p>If <span title=concept-request-header-list>header list</span> contains a
Expand Down Expand Up @@ -2997,8 +3003,9 @@ <h3>HTTP-network-or-cache fetch</h3>
<ol>
<li>
<p>If <var>httpRequest</var>'s <span title=concept-request-cache-mode>cache mode</span> is
"<code title>force-cache</code>", set <var>response</var> to the
<span title=concept-response>response</span> in the HTTP cache for <var>httpRequest</var>.
"<code title>force-cache</code>" or "<code title>only-if-cached</code>", then set
<var>response</var> to the <span title=concept-response>response</span> in the HTTP cache for
<var>httpRequest</var>.

<p class="note">As mandated by HTTP, this still takes the `<code title=http-vary>Vary</code>`
<span title=concept-header>header</span> into account.
Expand Down Expand Up @@ -3029,9 +3036,18 @@ <h3>HTTP-network-or-cache fetch</h3>
<span title=concept-header>headers</span>.
<!-- XXX xref partial, modify, resume headers -->

<li><p>If <var>response</var> is null, set <var>response</var> to the result of making an
<span title=concept-http-network-fetch>HTTP-network fetch</span> using <var>httpRequest</var> with
the <i title>credentials flag</i> set if set.
<li>
<p>If <var>response</var> is null, run these substeps:

<ol>
<li><p>If <var>httpRequest</var>'s <span title=concept-request-cache-mode>cache mode</span> is
"<code title>only-if-cached</code>", then return a
<span title=concept-network-error>network error</span>.

<li><p>Set <var>response</var> to the result of making an
<span title=concept-http-network-fetch>HTTP-network fetch</span> using <var>httpRequest</var>
with the <i title>credentials flag</i> set if set.
</ol>

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

<p class="note no-backref">"<code>serviceworker</code>" is omitted from
Expand Down Expand Up @@ -4395,6 +4411,11 @@ <h3>Request class</h3>
<var>request</var>'s <span title=concept-request-cache-mode>cache mode</span> to
it.

<li><p>If <var>request</var>'s <span title=concept-request-cache-mode>cache mode</span> is
"<code title>only-if-cached</code>" and <var>request</var>'s
<span title=concept-request-mode>mode</span> is <em>not</em> "<code title>same-origin</code>", then
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.

<li><p>If <var>init</var>'s <code title>redirect</code> member is present, set
<var>request</var>'s <span title=concept-request-redirect-mode>redirect mode</span>
to it.
Expand Down

0 comments on commit c721ac6

Please sign in to comment.