<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182071] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182071">182071</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-03-27 11:24:39 -0700 (Fri, 27 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WK2][NetworkCache] We only cache responses with status codes that are cacheable by default
https://bugs.webkit.org/show_bug.cgi?id=143125
&lt;rdar://problem/20321172&gt;

Reviewed by Antti Koivisto.

Source/WebCore:

Export a couple of extra symbols.

* platform/network/ResourceResponseBase.h:

Source/WebKit2:

We Previously only cached responses with status codes that are cacheable
by default [1]. However, RFC 7234 [2] allows us to cache responses with
other status codes, as long as they have explicit headers allowing
caching:
- 'Expires' header field
- 'max-age' response directive

This patch updates our caching policy accordingly to improve efficiency.

[1] http://tools.ietf.org/html/rfc7231#page-48
[2] http://tools.ietf.org/html/rfc7234#section-4.3.2

Test: http/tests/cache/disk-cache/disk-cache-307-status-code.html

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::canStore):

LayoutTests:

Add layout test to check that responses with status code 307 (which is not
cacheable by default) are cached if they have explicit expiration headers.

Also update a couple of other disk cache tests to cover heuristic
freshness (http://tools.ietf.org/html/rfc7234#section-4.2.2), relying on
'Last-Modified' header to estimate freshness if usual expiration headers
are not available.

* http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt:
* http/tests/cache/disk-cache/disk-cache-204-status-code.html:
* http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt: Added.
* http/tests/cache/disk-cache/disk-cache-307-status-code.html: Added.
* http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt:
* http/tests/cache/disk-cache/disk-cache-404-status-code.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache204statuscodeexpectedtxt">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache204statuscodehtml">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache404statuscodeexpectedtxt">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache404statuscodehtml">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceResponseBaseh">trunk/Source/WebCore/platform/network/ResourceResponseBase.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache307statuscodeexpectedtxt">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcache307statuscodehtml">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/LayoutTests/ChangeLog        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-03-27  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] We only cache responses with status codes that are cacheable by default
+        https://bugs.webkit.org/show_bug.cgi?id=143125
+        &lt;rdar://problem/20321172&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Add layout test to check that responses with status code 307 (which is not
+        cacheable by default) are cached if they have explicit expiration headers.
+
+        Also update a couple of other disk cache tests to cover heuristic
+        freshness (http://tools.ietf.org/html/rfc7234#section-4.2.2), relying on
+        'Last-Modified' header to estimate freshness if usual expiration headers
+        are not available.
+
+        * http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt:
+        * http/tests/cache/disk-cache/disk-cache-204-status-code.html:
+        * http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt: Added.
+        * http/tests/cache/disk-cache/disk-cache-307-status-code.html: Added.
+        * http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt:
+        * http/tests/cache/disk-cache/disk-cache-404-status-code.html:
+
</ins><span class="cx"> 2015-03-27  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed gardening.
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache204statuscodeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -3,7 +3,7 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-running 2 tests
</del><ins>+running 3 tests
</ins><span class="cx"> 
</span><span class="cx"> response headers: {&quot;Status&quot;:&quot;204&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
</span><span class="cx"> response source: Network
</span><span class="lines">@@ -11,6 +11,9 @@
</span><span class="cx"> response headers: {&quot;Status&quot;:&quot;204&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
</span><span class="cx"> response source: Disk cache
</span><span class="cx"> 
</span><ins>+response headers: {&quot;Status&quot;:&quot;204&quot;,&quot;Last-Modified&quot;:&quot;now(-1000)&quot;}
+response source: Disk cache
+
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache204statuscodehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -7,6 +7,7 @@
</span><span class="cx"> [
</span><span class="cx">  { responseHeaders: {'Status': '204', 'Cache-control': 'max-age=0' }, includeBody: false },
</span><span class="cx">  { responseHeaders: {'Status': '204', 'Cache-control': 'max-age=100' }, includeBody: false },
</span><ins>+ { responseHeaders: {'Status': '204', 'Last-Modified': 'now(-1000)' }, includeBody: false }, // Heuristic freshness.
</ins><span class="cx"> ];
</span><span class="cx"> 
</span><span class="cx"> description(&quot;Test that responses with HTTP status code 204 are cacheable&quot;);
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache307statuscodeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt (0 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code-expected.txt        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+Test that responses with HTTP status code 307 which are not cacheable by default
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+running 6 tests
+
+response headers: {&quot;Status&quot;:&quot;307&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Expires&quot;:&quot;now(0)&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Expires&quot;:&quot;now(100)&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Last-Modified&quot;:&quot;now(-1000)&quot;}
+response source: Network
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache307statuscodehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code.html (0 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-307-status-code.html        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+&lt;script src=&quot;/js-test-resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;resources/cache-test.js&quot;&gt;&lt;/script&gt;
+&lt;body&gt;
+&lt;script&gt;
+
+var tests =
+[
+ { responseHeaders: {'Status': '307'} },
+ { responseHeaders: {'Status': '307', 'Cache-control': 'max-age=0'} },
+ { responseHeaders: {'Status': '307', 'Cache-control': 'max-age=100'} },
+ { responseHeaders: {'Status': '307', 'Expires': 'now(0)'} },
+ { responseHeaders: {'Status': '307', 'Expires': 'now(100)'} },
+ { responseHeaders: {'Status': '307', 'Last-Modified': 'now(-1000)'} },
+];
+
+description(&quot;Test that responses with HTTP status code 307 which are not cacheable by default&quot;);
+
+debug(&quot;running &quot; + tests.length + &quot; tests&quot;);
+debug(&quot;&quot;);
+
+runTests(tests);
+
+&lt;/script&gt;
+&lt;script src=&quot;/js-test-resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache404statuscodeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code-expected.txt        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -3,7 +3,7 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-running 2 tests
</del><ins>+running 3 tests
</ins><span class="cx"> 
</span><span class="cx"> response headers: {&quot;Status&quot;:&quot;404&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
</span><span class="cx"> response source: Network
</span><span class="lines">@@ -11,6 +11,9 @@
</span><span class="cx"> response headers: {&quot;Status&quot;:&quot;404&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
</span><span class="cx"> response source: Disk cache
</span><span class="cx"> 
</span><ins>+response headers: {&quot;Status&quot;:&quot;404&quot;,&quot;Last-Modified&quot;:&quot;now(-1000)&quot;}
+response source: Disk cache
+
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcache404statuscodehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code.html (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code.html        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-404-status-code.html        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -7,6 +7,7 @@
</span><span class="cx"> [
</span><span class="cx">  { responseHeaders: {'Status': '404', 'Cache-control': 'max-age=0' } },
</span><span class="cx">  { responseHeaders: {'Status': '404', 'Cache-control': 'max-age=100' } },
</span><ins>+ { responseHeaders: {'Status': '404', 'Last-Modified': 'now(-1000)' } }, // Heuristic freshness.
</ins><span class="cx"> ];
</span><span class="cx"> 
</span><span class="cx"> description(&quot;Test that responses with HTTP status code 404 are cacheable&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/Source/WebCore/ChangeLog        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-03-27  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] We only cache responses with status codes that are cacheable by default
+        https://bugs.webkit.org/show_bug.cgi?id=143125
+        &lt;rdar://problem/20321172&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Export a couple of extra symbols.
+
+        * platform/network/ResourceResponseBase.h:
+
</ins><span class="cx"> 2015-03-27  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         HTMLMediaElement will fire 'seeked' before seek completes, leading to currentTime discontinuities.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceResponseBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.h (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceResponseBase.h        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.h        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -104,10 +104,10 @@
</span><span class="cx">     WEBCORE_EXPORT bool cacheControlContainsNoStore() const;
</span><span class="cx">     WEBCORE_EXPORT bool cacheControlContainsMustRevalidate() const;
</span><span class="cx">     WEBCORE_EXPORT bool hasCacheValidatorFields() const;
</span><del>-    double cacheControlMaxAge() const;
</del><ins>+    WEBCORE_EXPORT double cacheControlMaxAge() const;
</ins><span class="cx">     double date() const;
</span><span class="cx">     double age() const;
</span><del>-    double expires() const;
</del><ins>+    WEBCORE_EXPORT double expires() const;
</ins><span class="cx">     WEBCORE_EXPORT double lastModified() const;
</span><span class="cx"> 
</span><span class="cx">     enum class Source { Unknown, Network, DiskCache, DiskCacheAfterValidation };
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-03-27  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] We only cache responses with status codes that are cacheable by default
+        https://bugs.webkit.org/show_bug.cgi?id=143125
+        &lt;rdar://problem/20321172&gt;
+
+        Reviewed by Antti Koivisto.
+
+        We Previously only cached responses with status codes that are cacheable
+        by default [1]. However, RFC 7234 [2] allows us to cache responses with
+        other status codes, as long as they have explicit headers allowing
+        caching:
+        - 'Expires' header field
+        - 'max-age' response directive
+
+        This patch updates our caching policy accordingly to improve efficiency.
+
+        [1] http://tools.ietf.org/html/rfc7231#page-48
+        [2] http://tools.ietf.org/html/rfc7234#section-4.3.2
+
+        Test: http/tests/cache/disk-cache/disk-cache-307-status-code.html
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::canStore):
+
</ins><span class="cx"> 2015-03-26  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Respect cache-control directives in request
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182070 => 182071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-27 18:00:05 UTC (rev 182070)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-27 18:24:39 UTC (rev 182071)
</span><span class="lines">@@ -279,6 +279,44 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// http://tools.ietf.org/html/rfc7231#page-48
+static bool isStatusCodeCacheableByDefault(int statusCode)
+{
+    switch (statusCode) {
+    case 200: // OK
+    case 203: // Non-Authoritative Information
+    case 204: // No Content
+    case 300: // Multiple Choices
+    case 301: // Moved Permanently
+    case 404: // Not Found
+    case 405: // Method Not Allowed
+    case 410: // Gone
+    case 414: // URI Too Long
+    case 501: // Not Implemented
+        return true;
+    default:
+        return false;
+    }
+}
+
+static bool isStatusCodePotentiallyCacheable(int statusCode)
+{
+    switch (statusCode) {
+    case 201: // Created
+    case 202: // Accepted
+    case 205: // Reset Content
+    case 302: // Found
+    case 303: // See Other
+    case 307: // Temporary redirect
+    case 403: // Forbidden
+    case 406: // Not Acceptable
+    case 415: // Unsupported Media Type
+        return true;
+    default:
+        return false;
+    }
+}
+
</ins><span class="cx"> static StoreDecision canStore(const WebCore::ResourceRequest&amp; originalRequest, const WebCore::ResourceResponse&amp; response)
</span><span class="cx"> {
</span><span class="cx">     if (!originalRequest.url().protocolIsInHTTPFamily() || !response.isHTTP())
</span><span class="lines">@@ -294,20 +332,18 @@
</span><span class="cx">     if (response.cacheControlContainsNoStore())
</span><span class="cx">         return StoreDecision::NoDueToNoStoreResponse;
</span><span class="cx"> 
</span><del>-    switch (response.httpStatusCode()) {
-    case 200: // OK
-    case 203: // Non-Authoritative Information
-    case 204: // No Content
-    case 300: // Multiple Choices
-    case 301: // Moved Permanently
-    case 307: // Temporary Redirect
-    case 404: // Not Found
-    case 410: // Gone
</del><ins>+    if (isStatusCodeCacheableByDefault(response.httpStatusCode()))
</ins><span class="cx">         return StoreDecision::Yes;
</span><del>-    default:
-        LOG(NetworkCache, &quot;(NetworkProcess) status code %d&quot;, response.httpStatusCode());
</del><ins>+
+    if (isStatusCodePotentiallyCacheable(response.httpStatusCode())) {
+        // Check for expiration headers allowing us to cache.
+        // http://tools.ietf.org/html/rfc7234#section-4.3.2
+        if (std::isfinite(response.expires()) || std::isfinite(response.cacheControlMaxAge()))
+            return StoreDecision::Yes;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    LOG(NetworkCache, &quot;(NetworkProcess) status code %d not cacheable by default and no explicit expiration headers&quot;, response.httpStatusCode());
+
</ins><span class="cx">     return StoreDecision::NoDueToHTTPStatusCode;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>