<!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>[182145] 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/182145">182145</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-03-30 10:35:39 -0700 (Mon, 30 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WK2][NetworkCache] Add support for &quot;Cache-Control: max-stale&quot; request header
https://bugs.webkit.org/show_bug.cgi?id=143159
&lt;rdar://problem/20333296&gt;

Reviewed by Antti Koivisto.

Source/WebCore:

Add support for &quot;Cache-Control: max-stale&quot; request header:
https://tools.ietf.org/html/rfc7234#section-5.2.1.2

Test: http/tests/cache/disk-cache/disk-cache-request-max-stale.html

* platform/network/CacheValidation.cpp:
(WebCore::parseCacheControlDirectives):
* platform/network/CacheValidation.h:

Source/WebKit2:

Add support for &quot;Cache-Control: max-stale&quot; request header:
https://tools.ietf.org/html/rfc7234#section-5.2.1.2

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::responseHasExpired):
(WebKit::NetworkCache::requestRequiresRevalidation):
(WebKit::NetworkCache::canUse):

LayoutTests:

Add layout test to cover support for &quot;Cache-Control: max-stale&quot; request
header.

* http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt: Added.
* http/tests/cache/disk-cache/disk-cache-request-max-stale.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkCacheValidationcpp">trunk/Source/WebCore/platform/network/CacheValidation.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkCacheValidationh">trunk/Source/WebCore/platform/network/CacheValidation.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="#trunkLayoutTestshttptestscachediskcachediskcacherequestmaxstaleexpectedtxt">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcacherequestmaxstalehtml">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/LayoutTests/ChangeLog        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-03-30  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] Add support for &quot;Cache-Control: max-stale&quot; request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        &lt;rdar://problem/20333296&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Add layout test to cover support for &quot;Cache-Control: max-stale&quot; request
+        header.
+
+        * http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt: Added.
+        * http/tests/cache/disk-cache/disk-cache-request-max-stale.html: Added.
+
</ins><span class="cx"> 2015-03-30  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] When Web Audio is interrupted by a phone call, it cannot be restarted.
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcacherequestmaxstaleexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt (0 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -0,0 +1,155 @@
</span><ins>+Test for 'max-stale' request header
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+running 36 tests
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=0, max-age=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=0&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=100&quot;}
+response source: Network
+
+response headers: {&quot;Cache-control&quot;:&quot;max-age=100&quot;,&quot;Age&quot;:&quot;200&quot;}
+request headers: {&quot;Cache-control&quot;:&quot;max-stale=100, max-age=100&quot;}
+response source: Network
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcacherequestmaxstalehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale.html (0 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale.html        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -0,0 +1,38 @@
</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 testMatrix =
+[
+ [
+  { responseHeaders: {'Cache-control': 'max-age=0' } },
+  { responseHeaders: {'Cache-control': 'max-age=100' } },
+  ],
+ [
+   {},
+   { responseHeaders: {'Age': '200' } },
+  ],
+ [
+  { requestHeaders: {'Cache-control': 'max-stale=0' } },
+  { requestHeaders: {'Cache-control': 'max-stale' } },
+  { requestHeaders: {'Cache-control': 'max-stale=100' } },
+  ],
+ [
+  {},
+  { requestHeaders: {'Cache-control': 'max-age=0' } },
+  { requestHeaders: {'Cache-control': 'max-age=100' } },
+  ],
+ ];
+
+description(&quot;Test for 'max-stale' request header&quot;);
+
+var tests = generateTests(testMatrix);
+
+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="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/Source/WebCore/ChangeLog        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-03-30  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] Add support for &quot;Cache-Control: max-stale&quot; request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        &lt;rdar://problem/20333296&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Add support for &quot;Cache-Control: max-stale&quot; request header:
+        https://tools.ietf.org/html/rfc7234#section-5.2.1.2
+
+        Test: http/tests/cache/disk-cache/disk-cache-request-max-stale.html
+
+        * platform/network/CacheValidation.cpp:
+        (WebCore::parseCacheControlDirectives):
+        * platform/network/CacheValidation.h:
+
</ins><span class="cx"> 2015-03-30  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix iOS internal build after r182132.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkCacheValidationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/CacheValidation.cpp (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/CacheValidation.cpp        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/Source/WebCore/platform/network/CacheValidation.cpp        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -274,6 +274,21 @@
</span><span class="cx">                 double maxAge = directives[i].second.toDouble(&amp;ok);
</span><span class="cx">                 if (ok)
</span><span class="cx">                     result.maxAge = maxAge;
</span><ins>+            } else if (equalIgnoringCase(directives[i].first, &quot;max-stale&quot;)) {
+                // https://tools.ietf.org/html/rfc7234#section-5.2.1.2
+                if (!std::isnan(result.maxStale)) {
+                    // First max-stale directive wins if there are multiple ones.
+                    continue;
+                }
+                if (directives[i].second.isEmpty()) {
+                    // if no value is assigned to max-stale, then the client is willing to accept a stale response of any age.
+                    result.maxStale = std::numeric_limits&lt;double&gt;::max();
+                    continue;
+                }
+                bool ok;
+                double maxStale = directives[i].second.toDouble(&amp;ok);
+                if (ok)
+                    result.maxStale = maxStale;
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkCacheValidationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/CacheValidation.h (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/CacheValidation.h        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/Source/WebCore/platform/network/CacheValidation.h        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -55,6 +55,7 @@
</span><span class="cx"> 
</span><span class="cx"> struct CacheControlDirectives {
</span><span class="cx">     double maxAge { std::numeric_limits&lt;double&gt;::quiet_NaN() };
</span><ins>+    double maxStale { std::numeric_limits&lt;double&gt;::quiet_NaN() };
</ins><span class="cx">     bool noCache { false };
</span><span class="cx">     bool noStore { false };
</span><span class="cx">     bool mustRevalidate { false };
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-03-30  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][NetworkCache] Add support for &quot;Cache-Control: max-stale&quot; request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        &lt;rdar://problem/20333296&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Add support for &quot;Cache-Control: max-stale&quot; request header:
+        https://tools.ietf.org/html/rfc7234#section-5.2.1.2
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::responseHasExpired):
+        (WebKit::NetworkCache::requestRequiresRevalidation):
+        (WebKit::NetworkCache::canUse):
+
</ins><span class="cx"> 2015-03-30  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL][GTK] WebKit2's generate-forwarding-headers.pl should fail if clashing headers found
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182144 => 182145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-30 17:35:39 UTC (rev 182145)
</span><span class="lines">@@ -150,7 +150,7 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool responseHasExpired(const WebCore::ResourceResponse&amp; response, std::chrono::milliseconds timestamp)
</del><ins>+static bool responseHasExpired(const WebCore::ResourceResponse&amp; response, std::chrono::milliseconds timestamp, double maxStale)
</ins><span class="cx"> {
</span><span class="cx">     if (response.cacheControlContainsNoCache())
</span><span class="cx">         return true;
</span><span class="lines">@@ -159,17 +159,18 @@
</span><span class="cx">     double age = WebCore::computeCurrentAge(response, doubleTimeStamp.count());
</span><span class="cx">     double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, doubleTimeStamp.count());
</span><span class="cx"> 
</span><del>-    bool hasExpired = age &gt; lifetime;
</del><ins>+    maxStale = std::isnan(maxStale) ? 0 : maxStale;
+    bool hasExpired = age - lifetime &gt; maxStale;
</ins><span class="cx"> 
</span><span class="cx"> #ifndef LOG_DISABLED
</span><span class="cx">     if (hasExpired)
</span><del>-        LOG(NetworkCache, &quot;(NetworkProcess) needsRevalidation hasExpired age=%f lifetime=%f&quot;, age, lifetime);
</del><ins>+        LOG(NetworkCache, &quot;(NetworkProcess) needsRevalidation hasExpired age=%f lifetime=%f max-stale=%g&quot;, age, lifetime, maxStale);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     return hasExpired;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool requestRequiresRevalidation(const WebCore::ResourceRequest&amp; request)
</del><ins>+static bool responseNeedsRevalidation(const WebCore::ResourceResponse&amp; response, const WebCore::ResourceRequest&amp; request, std::chrono::milliseconds timestamp)
</ins><span class="cx"> {
</span><span class="cx">     auto requestDirectives = WebCore::parseCacheControlDirectives(request.httpHeaderFields());
</span><span class="cx">     if (requestDirectives.noCache)
</span><span class="lines">@@ -178,7 +179,7 @@
</span><span class="cx">     if (requestDirectives.maxAge == 0)
</span><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    return false;
</del><ins>+    return responseHasExpired(response, timestamp, requestDirectives.maxStale);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static UseDecision canUse(const Entry&amp; entry, const WebCore::ResourceRequest&amp; request)
</span><span class="lines">@@ -192,8 +193,7 @@
</span><span class="cx">     if (cachePolicyAllowsExpired(request.cachePolicy()))
</span><span class="cx">         return UseDecision::Use;
</span><span class="cx"> 
</span><del>-    bool needsRevalidation = requestRequiresRevalidation(request) || responseHasExpired(entry.response(), entry.timeStamp());
-    if (!needsRevalidation)
</del><ins>+    if (!responseNeedsRevalidation(entry.response(), request, entry.timeStamp()))
</ins><span class="cx">         return UseDecision::Use;
</span><span class="cx"> 
</span><span class="cx">     bool hasValidatorFields = entry.response().hasCacheValidatorFields();
</span></span></pre>
</div>
</div>

</body>
</html>