<!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>[194313] 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/194313">194313</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-12-19 05:26:38 -0800 (Sat, 19 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cache redirects as separate entries
https://bugs.webkit.org/show_bug.cgi?id=152424

Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/cache/disk-cache/disk-cache-redirect.html

* platform/network/ResourceRequestBase.h:

Source/WebKit2:

We are currently caching redirect chains. This has correctness issues and can be inefficient in cases
where multiple URLs redirect to the same destination.

After this patch we write a cache entry for each redirect individually.

* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::sharedWillSendRedirectedRequest):
* NetworkProcess/NetworkLoad.h:
(WebKit::NetworkLoad::currentRequest):
(WebKit::NetworkLoad::clearCurrentRequest):
* NetworkProcess/NetworkLoadClient.h:

    Add original request as a parameter for willSendRedirectedRequest.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::~NetworkResourceLoader):
(WebKit::NetworkResourceLoader::canUseCache):

    Factor to a function.

(WebKit::NetworkResourceLoader::isSynchronous):
(WebKit::NetworkResourceLoader::start):
(WebKit::NetworkResourceLoader::retrieveCacheEntry):

    Factor to a function.
    Call dispatchWillSendRequestForCacheEntry for cached redirects.

(WebKit::NetworkResourceLoader::startNetworkLoad):

    Make this take request as argument instead of always loading originalRequest().

(WebKit::NetworkResourceLoader::abort):
(WebKit::NetworkResourceLoader::didFinishLoading):

    Remove redirect chain code.
    Store cache entry for current request instead of the original request.

(WebKit::NetworkResourceLoader::didFailLoading):
(WebKit::NetworkResourceLoader::willSendRedirectedRequest):

    Write cache entry for redirect.

(WebKit::NetworkResourceLoader::continueWillSendRequest):

    If we are playing back cached redirect continue with another cache lookup.

(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):

    No need to synthesize fake willSendRequest anymore.

(WebKit::NetworkResourceLoader::validateCacheEntry):
(WebKit::NetworkResourceLoader::dispatchWillSendRequestForCacheEntry):

    Route via web process willSendRequest so cached redirects looks exactly like network ones.

(WebKit::NetworkResourceLoader::messageSenderConnection):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::makeUseDecision):

    Ignore validation headers for cached redirects.

(WebKit::NetworkCache::makeRetrieveDecision):
(WebKit::NetworkCache::makeStoreDecision):
(WebKit::NetworkCache::Cache::retrieve):
(WebKit::NetworkCache::Cache::store):

    Rename originalRequest -&gt; request since it is not really the original request anymore in all cases.

(WebKit::NetworkCache::Cache::storeRedirect):

    Stored redirects include the network layer generated ResourceRequest instead of body data.

(WebKit::NetworkCache::Cache::update):
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::Entry):

    New constructor for making redirect entries.

(WebKit::NetworkCache::Entry::encodeAsStorageRecord):
(WebKit::NetworkCache::Entry::decodeStorageRecord):

    Encoding support.

* NetworkProcess/cache/NetworkCacheEntry.h:
(WebKit::NetworkCache::Entry::varyingRequestHeaders):
(WebKit::NetworkCache::Entry::redirectRequest):
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::~SpeculativeLoad):
(WebKit::NetworkCache::SpeculativeLoad::willSendRedirectedRequest):
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
* NetworkProcess/cache/NetworkCacheStatistics.cpp:
(WebKit::NetworkCache::cachedEntryReuseFailureToDiagnosticKey):

LayoutTests:

* http/tests/cache/disk-cache/disk-cache-redirect-expected.txt: Added.
* http/tests/cache/disk-cache/disk-cache-redirect.html: Added.
* http/tests/cache/disk-cache/resources/generate-response.cgi:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcacheresourcesgenerateresponsecgi">trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceRequestBaseh">trunk/Source/WebCore/platform/network/ResourceRequestBase.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkLoadcpp">trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkLoadh">trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkLoadClienth">trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp">trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkResourceLoaderh">trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntryh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadcpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticscpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcacheredirectexpectedtxt">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscachediskcachediskcacheredirecthtml">trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/LayoutTests/ChangeLog        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-12-18  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Cache redirects as separate entries
+        https://bugs.webkit.org/show_bug.cgi?id=152424
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/cache/disk-cache/disk-cache-redirect-expected.txt: Added.
+        * http/tests/cache/disk-cache/disk-cache-redirect.html: Added.
+        * http/tests/cache/disk-cache/resources/generate-response.cgi:
+
</ins><span class="cx"> 2015-12-18  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Mark fast/regions/overflow/overflow-region-float.html as passing
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcacheredirectexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect-expected.txt (0 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect-expected.txt        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -0,0 +1,122 @@
</span><ins>+Test redirect caching
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+running 12 tests
+
+--------Testing loads from disk cache--------
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Disk cache
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Disk cache
+
+--------Testing loads through memory cache (XHR behavior)--------
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+--------Testing loads through memory cache (subresource behavior)--------
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=0&quot;}
+response source: Network
+
+response headers: {&quot;Status&quot;:&quot;301&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;302&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;303&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+response headers: {&quot;Status&quot;:&quot;307&quot;,&quot;Location&quot;:&quot;unique-cacheable&quot;,&quot;Cache-control&quot;:&quot;max-age=100&quot;}
+response source: Memory cache
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscachediskcachediskcacheredirecthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect.html (0 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-redirect.html        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -0,0 +1,31 @@
</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: {'Status': '301', 'Location': 'unique-cacheable' } },
+  { responseHeaders: {'Status': '302', 'Location': 'unique-cacheable' } },
+  { responseHeaders: {'Status': '303', 'Location': 'unique-cacheable' } },
+  { responseHeaders: {'Status': '307', 'Location': 'unique-cacheable' } },
+  ],
+ [
+  { },
+  { responseHeaders: {'Cache-control': 'max-age=0' } },
+  { responseHeaders: {'Cache-control': 'max-age=100' } },
+  ],
+ ];
+
+description(&quot;Test redirect caching&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="trunkLayoutTestshttptestscachediskcacheresourcesgenerateresponsecgi"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -8,12 +8,24 @@
</span><span class="cx"> my $expiresInFutureIn304 = $query-&gt;param('expires-in-future-in-304') || 0;
</span><span class="cx"> my $delay = $query-&gt;param('delay') || 0;
</span><span class="cx"> my $body = $query-&gt;param('body') || 0;
</span><ins>+my $status = $query-&gt;param('Status') || 0;
</ins><span class="cx"> 
</span><span class="cx"> if ($body eq &quot;unique&quot;) {
</span><span class="cx">     $body = sprintf &quot;%08X\n&quot;, rand(0xffffffff)
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> my $hasStatusCode = 0;
</span><ins>+my $hasLocation = 0;
+if ($status == 301 || $status == 302 || $status == 303 || $status == 307) {
+    if ($query-&gt;param('Location') eq &quot;unique-cacheable&quot;) {
+        my $redirectBody = sprintf &quot;%08X&quot;, rand(0xffffffff);
+        print &quot;Status: &quot;. $status . &quot;\n&quot;;
+        print &quot;Location: generate-response.cgi?body=&quot; . $redirectBody . &quot;&amp;Cache-control=max-age%3D1000&amp;uniqueId=&quot; . $query-&gt;param('uniqueId') . &quot;\n&quot;;
+        $hasLocation = 1;
+        $hasStatusCode = 1;
+    }
+}
+
</ins><span class="cx"> my $hasExpiresHeader = 0;
</span><span class="cx"> if ($query-&gt;http &amp;&amp; $query-&gt;http(&quot;If-None-Match&quot;) eq &quot;match&quot;) {
</span><span class="cx">     print &quot;Status: 304\n&quot;;
</span><span class="lines">@@ -29,7 +41,7 @@
</span><span class="cx">     if ($1 &lt; 6 &amp;&amp; $2 &lt; 6) {
</span><span class="cx">         print &quot;Status: 206\n&quot;;
</span><span class="cx">     } else {
</span><del>-        print &quot;Status: 416\n&quot;;
</del><ins>+        print &quot;Status: 416\n&quot;;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     $hasStatusCode = 1;
</span><span class="lines">@@ -39,6 +51,7 @@
</span><span class="cx">     next if ($_ eq &quot;uniqueId&quot;);
</span><span class="cx">     next if ($_ eq &quot;delay&quot;);
</span><span class="cx">     next if ($_ eq &quot;body&quot;);
</span><ins>+    next if ($_ eq &quot;Location&quot; and $hasLocation);
</ins><span class="cx">     next if ($_ eq &quot;Status&quot; and $hasStatusCode);
</span><span class="cx">     next if ($_ eq &quot;Expires&quot; and $hasExpiresHeader);
</span><span class="cx">     print $_ . &quot;: &quot; . $query-&gt;param($_) . &quot;\n&quot;;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebCore/ChangeLog        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-12-18  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Cache redirects as separate entries
+        https://bugs.webkit.org/show_bug.cgi?id=152424
+
+        Reviewed by Alex Christensen.
+
+        Test: http/tests/cache/disk-cache/disk-cache-redirect.html
+
+        * platform/network/ResourceRequestBase.h:
+
</ins><span class="cx"> 2015-12-18  Per Arne Vollan  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WinCairo] Empty context menu item.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceRequestBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -54,10 +54,10 @@
</span><span class="cx">     class ResourceRequestBase {
</span><span class="cx">         WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     public:
</span><del>-        static std::unique_ptr&lt;ResourceRequest&gt; adopt(std::unique_ptr&lt;CrossThreadResourceRequestData&gt;);
</del><ins>+        WEBCORE_EXPORT static std::unique_ptr&lt;ResourceRequest&gt; adopt(std::unique_ptr&lt;CrossThreadResourceRequestData&gt;);
</ins><span class="cx"> 
</span><span class="cx">         // Gets a copy of the data suitable for passing to another thread.
</span><del>-        std::unique_ptr&lt;CrossThreadResourceRequestData&gt; copyData() const;
</del><ins>+        WEBCORE_EXPORT std::unique_ptr&lt;CrossThreadResourceRequestData&gt; copyData() const;
</ins><span class="cx"> 
</span><span class="cx">         WEBCORE_EXPORT bool isNull() const;
</span><span class="cx">         WEBCORE_EXPORT bool isEmpty() const;
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/ChangeLog        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -1,3 +1,105 @@
</span><ins>+2015-12-18  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Cache redirects as separate entries
+        https://bugs.webkit.org/show_bug.cgi?id=152424
+
+        Reviewed by Alex Christensen.
+
+        We are currently caching redirect chains. This has correctness issues and can be inefficient in cases
+        where multiple URLs redirect to the same destination.
+
+        After this patch we write a cache entry for each redirect individually.
+
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::sharedWillSendRedirectedRequest):
+        * NetworkProcess/NetworkLoad.h:
+        (WebKit::NetworkLoad::currentRequest):
+        (WebKit::NetworkLoad::clearCurrentRequest):
+        * NetworkProcess/NetworkLoadClient.h:
+
+            Add original request as a parameter for willSendRedirectedRequest.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::~NetworkResourceLoader):
+        (WebKit::NetworkResourceLoader::canUseCache):
+
+            Factor to a function.
+
+        (WebKit::NetworkResourceLoader::isSynchronous):
+        (WebKit::NetworkResourceLoader::start):
+        (WebKit::NetworkResourceLoader::retrieveCacheEntry):
+
+            Factor to a function.
+            Call dispatchWillSendRequestForCacheEntry for cached redirects.
+
+        (WebKit::NetworkResourceLoader::startNetworkLoad):
+
+            Make this take request as argument instead of always loading originalRequest().
+
+        (WebKit::NetworkResourceLoader::abort):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+
+            Remove redirect chain code.
+            Store cache entry for current request instead of the original request.
+
+        (WebKit::NetworkResourceLoader::didFailLoading):
+        (WebKit::NetworkResourceLoader::willSendRedirectedRequest):
+
+            Write cache entry for redirect.
+
+        (WebKit::NetworkResourceLoader::continueWillSendRequest):
+
+            If we are playing back cached redirect continue with another cache lookup.
+
+        (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+
+            No need to synthesize fake willSendRequest anymore.
+
+        (WebKit::NetworkResourceLoader::validateCacheEntry):
+        (WebKit::NetworkResourceLoader::dispatchWillSendRequestForCacheEntry):
+
+            Route via web process willSendRequest so cached redirects looks exactly like network ones.
+
+        (WebKit::NetworkResourceLoader::messageSenderConnection):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::makeUseDecision):
+
+            Ignore validation headers for cached redirects.
+
+        (WebKit::NetworkCache::makeRetrieveDecision):
+        (WebKit::NetworkCache::makeStoreDecision):
+        (WebKit::NetworkCache::Cache::retrieve):
+        (WebKit::NetworkCache::Cache::store):
+
+            Rename originalRequest -&gt; request since it is not really the original request anymore in all cases.
+
+        (WebKit::NetworkCache::Cache::storeRedirect):
+
+            Stored redirects include the network layer generated ResourceRequest instead of body data.
+
+        (WebKit::NetworkCache::Cache::update):
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::Entry):
+
+            New constructor for making redirect entries.
+
+        (WebKit::NetworkCache::Entry::encodeAsStorageRecord):
+        (WebKit::NetworkCache::Entry::decodeStorageRecord):
+
+            Encoding support.
+
+        * NetworkProcess/cache/NetworkCacheEntry.h:
+        (WebKit::NetworkCache::Entry::varyingRequestHeaders):
+        (WebKit::NetworkCache::Entry::redirectRequest):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
+        (WebKit::NetworkCache::SpeculativeLoad::~SpeculativeLoad):
+        (WebKit::NetworkCache::SpeculativeLoad::willSendRedirectedRequest):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
+        * NetworkProcess/cache/NetworkCacheStatistics.cpp:
+        (WebKit::NetworkCache::cachedEntryReuseFailureToDiagnosticKey):
+
</ins><span class="cx"> 2015-12-18  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Avoid triggering clang's -Wundefined-bool-conversion
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkLoadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -149,8 +149,9 @@
</span><span class="cx">     ASSERT(!redirectResponse.isNull());
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><ins>+    auto oldRequest = m_currentRequest;
</ins><span class="cx">     m_currentRequest = request;
</span><del>-    m_client.willSendRedirectedRequest(request, redirectResponse);
</del><ins>+    m_client.willSendRedirectedRequest(oldRequest, request, redirectResponse);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(NETWORK_SESSION)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkLoadh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoad.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx">     void setDefersLoading(bool);
</span><span class="cx">     void cancel();
</span><span class="cx"> 
</span><ins>+    const WebCore::ResourceRequest&amp; currentRequest() const { return m_currentRequest; }
</ins><span class="cx">     void clearCurrentRequest() { m_currentRequest = WebCore::ResourceRequest(); }
</span><span class="cx"> 
</span><span class="cx">     void continueWillSendRequest(const WebCore::ResourceRequest&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkLoadClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkLoadClient.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -50,7 +50,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) = 0;
</span><span class="cx">     virtual void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&amp;) = 0;
</span><del>-    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp; redirectResponse) = 0;
</del><ins>+    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceRequest&amp; redirectRequest, const WebCore::ResourceResponse&amp; redirectResponse) = 0;
</ins><span class="cx">     enum class ShouldContinueDidReceiveResponse { No, Yes };
</span><span class="cx">     virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&amp;) = 0;
</span><span class="cx">     virtual void didReceiveBuffer(RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp;, int reportedEncodedDataLength) = 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -107,6 +107,19 @@
</span><span class="cx">     ASSERT(!isSynchronous() || !m_synchronousLoadData-&gt;delayedReply);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(NETWORK_CACHE)
+bool NetworkResourceLoader::canUseCache(const ResourceRequest&amp; request) const
+{
+    if (!NetworkCache::singleton().isEnabled())
+        return false;
+    if (sessionID().isEphemeral())
+        return false;
+    if (!request.url().protocolIsInHTTPFamily())
+        return false;
+    return true;
+}
+#endif
+
</ins><span class="cx"> bool NetworkResourceLoader::isSynchronous() const
</span><span class="cx"> {
</span><span class="cx">     return !!m_synchronousLoadData;
</span><span class="lines">@@ -120,23 +133,36 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><del>-    if (!NetworkCache::singleton().isEnabled() || sessionID().isEphemeral() || !originalRequest().url().protocolIsInHTTPFamily()) {
-        startNetworkLoad();
</del><ins>+    if (canUseCache(originalRequest())) {
+        retrieveCacheEntry(originalRequest());
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><ins>+#endif
</ins><span class="cx"> 
</span><ins>+    startNetworkLoad(originalRequest());
+}
+
+#if ENABLE(NETWORK_CACHE)
+void NetworkResourceLoader::retrieveCacheEntry(const ResourceRequest&amp; request)
+{
+    ASSERT(canUseCache(request));
+
</ins><span class="cx">     RefPtr&lt;NetworkResourceLoader&gt; loader(this);
</span><del>-    NetworkCache::singleton().retrieve(originalRequest(), { m_parameters.webPageID, m_parameters.webFrameID }, [loader](std::unique_ptr&lt;NetworkCache::Entry&gt; entry) {
</del><ins>+    NetworkCache::singleton().retrieve(request, { m_parameters.webPageID, m_parameters.webFrameID }, [loader, request](std::unique_ptr&lt;NetworkCache::Entry&gt; entry) {
</ins><span class="cx">         if (loader-&gt;hasOneRef()) {
</span><span class="cx">             // The loader has been aborted and is only held alive by this lambda.
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         if (!entry) {
</span><del>-            loader-&gt;startNetworkLoad();
</del><ins>+            loader-&gt;startNetworkLoad(request);
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><ins>+        if (entry-&gt;redirectRequest()) {
+            loader-&gt;dispatchWillSendRequestForCacheEntry(WTF::move(entry));
+            return;
+        }
</ins><span class="cx">         if (loader-&gt;m_parameters.needsCertificateInfo &amp;&amp; !entry-&gt;response().containsCertificateInfo()) {
</span><del>-            loader-&gt;startNetworkLoad();
</del><ins>+            loader-&gt;startNetworkLoad(request);
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         if (entry-&gt;needsValidation()) {
</span><span class="lines">@@ -145,12 +171,10 @@
</span><span class="cx">         }
</span><span class="cx">         loader-&gt;didRetrieveCacheEntry(WTF::move(entry));
</span><span class="cx">     });
</span><del>-#else
-    startNetworkLoad();
</del><ins>+}
</ins><span class="cx"> #endif
</span><del>-}
</del><span class="cx"> 
</span><del>-void NetworkResourceLoader::startNetworkLoad(const Optional&lt;ResourceRequest&gt;&amp; updatedRequest)
</del><ins>+void NetworkResourceLoader::startNetworkLoad(const ResourceRequest&amp; request)
</ins><span class="cx"> {
</span><span class="cx">     consumeSandboxExtensions();
</span><span class="cx"> 
</span><span class="lines">@@ -158,14 +182,13 @@
</span><span class="cx">         m_bufferedData = SharedBuffer::create();
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><del>-    if (NetworkCache::singleton().isEnabled())
</del><ins>+    if (canUseCache(request))
</ins><span class="cx">         m_bufferedDataForCache = SharedBuffer::create();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     NetworkLoadParameters parameters = m_parameters;
</span><span class="cx">     parameters.defersLoading = m_defersLoading;
</span><del>-    if (updatedRequest)
-        parameters.request = updatedRequest.value();
</del><ins>+    parameters.request = request;
</ins><span class="cx">     m_networkLoad = std::make_unique&lt;NetworkLoad&gt;(*this, parameters);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -212,15 +235,14 @@
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><span class="cx">     if (m_networkLoad &amp;&amp; !m_didConvertToDownload) {
</span><del>-        m_networkLoad-&gt;cancel();
-
</del><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><del>-        if (NetworkCache::singleton().isEnabled()) {
</del><ins>+        if (canUseCache(m_networkLoad-&gt;currentRequest())) {
</ins><span class="cx">             // We might already have used data from this incomplete load. Ensure older versions don't remain in the cache after cancel.
</span><span class="cx">             if (!m_response.isNull())
</span><del>-                NetworkCache::singleton().remove(originalRequest());
</del><ins>+                NetworkCache::singleton().remove(m_networkLoad-&gt;currentRequest());
</ins><span class="cx">         }
</span><span class="cx"> #endif
</span><ins>+        m_networkLoad-&gt;cancel();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     cleanup();
</span><span class="lines">@@ -302,7 +324,7 @@
</span><span class="cx"> void NetworkResourceLoader::didFinishLoading(double finishTime)
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><del>-    if (NetworkCache::singleton().isEnabled()) {
</del><ins>+    if (canUseCache(m_networkLoad-&gt;currentRequest())) {
</ins><span class="cx">         if (m_cacheEntryForValidation) {
</span><span class="cx">             // 304 Not Modified
</span><span class="cx">             ASSERT(m_response.httpStatusCode() == 304);
</span><span class="lines">@@ -310,21 +332,13 @@
</span><span class="cx">             didRetrieveCacheEntry(WTF::move(m_cacheEntryForValidation));
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        bool allowStale = originalRequest().cachePolicy() &gt;= ReturnCacheDataElseLoad;
-        bool hasCacheableRedirect = m_response.isHTTP() &amp;&amp; redirectChainAllowsReuse(m_redirectChainCacheStatus, allowStale ? ReuseExpiredRedirection : DoNotReuseExpiredRedirection);
-        if (hasCacheableRedirect &amp;&amp; m_redirectChainCacheStatus.status == RedirectChainCacheStatus::CachedRedirection) {
-            // Maybe we should cache the actual redirects instead of the end result?
-            auto now = std::chrono::system_clock::now();
-            auto responseEndOfValidity = now + computeFreshnessLifetimeForHTTPFamily(m_response, now) - computeCurrentAge(m_response, now);
-            hasCacheableRedirect = responseEndOfValidity &lt;= m_redirectChainCacheStatus.endOfValidity;
-        }
</del><span class="cx"> 
</span><span class="cx">         bool isPrivateSession = sessionID().isEphemeral();
</span><del>-        if (m_bufferedDataForCache &amp;&amp; hasCacheableRedirect &amp;&amp; !isPrivateSession) {
</del><ins>+        if (m_bufferedDataForCache &amp;&amp; m_response.isHTTP() &amp;&amp; !isPrivateSession) {
</ins><span class="cx">             // Keep the connection alive.
</span><span class="cx">             RefPtr&lt;NetworkConnectionToWebProcess&gt; connection(&amp;connectionToWebProcess());
</span><span class="cx">             RefPtr&lt;NetworkResourceLoader&gt; loader(this);
</span><del>-            NetworkCache::singleton().store(originalRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody&amp; mappedBody) {
</del><ins>+            NetworkCache::singleton().store(m_networkLoad-&gt;currentRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody&amp; mappedBody) {
</ins><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="cx">                 if (mappedBody.shareableResourceHandle.isNull())
</span><span class="cx">                     return;
</span><span class="lines">@@ -332,9 +346,6 @@
</span><span class="cx">                 loader-&gt;send(Messages::NetworkProcessConnection::DidCacheResource(loader-&gt;originalRequest(), mappedBody.shareableResourceHandle, loader-&gt;sessionID()));
</span><span class="cx"> #endif
</span><span class="cx">             });
</span><del>-        } else if (!hasCacheableRedirect) {
-            // Make sure we don't keep a stale entry in the cache.
-            NetworkCache::singleton().remove(originalRequest());
</del><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -371,17 +382,13 @@
</span><span class="cx">     cleanup();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void NetworkResourceLoader::willSendRedirectedRequest(const ResourceRequest&amp; request, const ResourceResponse&amp; redirectResponse)
</del><ins>+void NetworkResourceLoader::willSendRedirectedRequest(const ResourceRequest&amp; request, const WebCore::ResourceRequest&amp; redirectRequest, const ResourceResponse&amp; redirectResponse)
</ins><span class="cx"> {
</span><del>-#if ENABLE(NETWORK_CACHE)
-    updateRedirectChainStatus(m_redirectChainCacheStatus, redirectResponse);
-#endif
-
</del><span class="cx">     if (isSynchronous()) {
</span><del>-        ResourceRequest overridenRequest = request;
</del><ins>+        ResourceRequest overridenRequest = redirectRequest;
</ins><span class="cx">         // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
</span><span class="cx">         // This includes at least updating host records, and comparing the current request instead of the original request here.
</span><del>-        if (!protocolHostAndPortAreEqual(originalRequest().url(), request.url())) {
</del><ins>+        if (!protocolHostAndPortAreEqual(originalRequest().url(), redirectRequest.url())) {
</ins><span class="cx">             ASSERT(m_synchronousLoadData-&gt;error.isNull());
</span><span class="cx">             m_synchronousLoadData-&gt;error = SynchronousLoaderClient::platformBadResponseError();
</span><span class="cx">             m_networkLoad-&gt;clearCurrentRequest();
</span><span class="lines">@@ -390,11 +397,30 @@
</span><span class="cx">         continueWillSendRequest(overridenRequest);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-    sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(request, redirectResponse));
</del><ins>+    sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(redirectRequest, redirectResponse));
+
+#if ENABLE(NETWORK_CACHE)
+    if (canUseCache(request))
+        NetworkCache::singleton().storeRedirect(request, redirectResponse, redirectRequest);
+#else
+    UNUSED_PARAM(request);
+#endif
</ins><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> void NetworkResourceLoader::continueWillSendRequest(const ResourceRequest&amp; newRequest)
</span><span class="cx"> {
</span><ins>+#if ENABLE(NETWORK_CACHE)
+    if (m_isWaitingContinueWillSendRequestForCachedRedirect) {
+        LOG(NetworkCache, &quot;(NetworkProcess) Retrieving cached redirect&quot;);
+        if (canUseCache(newRequest))
+            retrieveCacheEntry(newRequest);
+        else
+            startNetworkLoad(newRequest);
+
+        m_isWaitingContinueWillSendRequestForCachedRedirect = false;
+        return;
+    }
+#endif
</ins><span class="cx">     m_networkLoad-&gt;continueWillSendRequest(newRequest);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -463,14 +489,6 @@
</span><span class="cx">         m_synchronousLoadData-&gt;response = entry-&gt;response();
</span><span class="cx">         sendReplyToSynchronousRequest(*m_synchronousLoadData, entry-&gt;buffer());
</span><span class="cx">     } else {
</span><del>-        if (entry-&gt;response().url() != originalRequest().url()) {
-            // This is a cached redirect. Synthesize a minimal redirect so we get things like referer header right.
-            // FIXME: We should cache the actual redirects.
-            ResourceRequest syntheticRedirectRequest(entry-&gt;response().url());
-            ResourceResponse syntheticRedirectResponse(originalRequest().url(), { }, 0, { });
-            sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(syntheticRedirectRequest, syntheticRedirectResponse));
-        }
-
</del><span class="cx">         bool needsContinueDidReceiveResponseMessage = originalRequest().requester() == ResourceRequest::Requester::Main;
</span><span class="cx">         sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(entry-&gt;response(), needsContinueDidReceiveResponseMessage));
</span><span class="cx"> 
</span><span class="lines">@@ -511,6 +529,15 @@
</span><span class="cx"> 
</span><span class="cx">     startNetworkLoad(revalidationRequest);
</span><span class="cx"> }
</span><ins>+
+void NetworkResourceLoader::dispatchWillSendRequestForCacheEntry(std::unique_ptr&lt;NetworkCache::Entry&gt; entry)
+{
+    ASSERT(entry-&gt;redirectRequest());
+    LOG(NetworkCache, &quot;(NetworkProcess) Executing cached redirect&quot;);
+
+    sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(*entry-&gt;redirectRequest(), entry-&gt;response()));
+    m_isWaitingContinueWillSendRequestForCachedRedirect = true;
+}
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> IPC::Connection* NetworkResourceLoader::messageSenderConnection()
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkResourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -61,6 +61,10 @@
</span><span class="cx"> 
</span><span class="cx">     NetworkLoad* networkLoad() const { return m_networkLoad.get(); }
</span><span class="cx"> 
</span><ins>+#if ENABLE(NETWORK_CACHE)
+    bool canUseCache(const WebCore::ResourceRequest&amp;) const;
+#endif
+
</ins><span class="cx">     void start();
</span><span class="cx">     void abort();
</span><span class="cx"> 
</span><span class="lines">@@ -97,7 +101,7 @@
</span><span class="cx">     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
</span><span class="cx">     virtual void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&amp;) override;
</span><span class="cx">     virtual bool isSynchronous() const override;
</span><del>-    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp; redirectResponse) override;
</del><ins>+    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceRequest&amp; redirectRequest, const WebCore::ResourceResponse&amp; redirectResponse) override;
</ins><span class="cx">     virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&amp;) override;
</span><span class="cx">     virtual void didReceiveBuffer(RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp;, int reportedEncodedDataLength) override;
</span><span class="cx">     virtual void didFinishLoading(double finishTime) override;
</span><span class="lines">@@ -112,11 +116,13 @@
</span><span class="cx">     virtual uint64_t messageSenderDestinationID() override { return m_parameters.identifier; }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><ins>+    void retrieveCacheEntry(const WebCore::ResourceRequest&amp;);
</ins><span class="cx">     void didRetrieveCacheEntry(std::unique_ptr&lt;NetworkCache::Entry&gt;);
</span><span class="cx">     void validateCacheEntry(std::unique_ptr&lt;NetworkCache::Entry&gt;);
</span><ins>+    void dispatchWillSendRequestForCacheEntry(std::unique_ptr&lt;NetworkCache::Entry&gt;);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    void startNetworkLoad(const Optional&lt;WebCore::ResourceRequest&gt;&amp; updatedRequest = { });
</del><ins>+    void startNetworkLoad(const WebCore::ResourceRequest&amp;);
</ins><span class="cx">     void continueDidReceiveResponse();
</span><span class="cx"> 
</span><span class="cx">     void cleanup();
</span><span class="lines">@@ -155,8 +161,7 @@
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><span class="cx">     RefPtr&lt;WebCore::SharedBuffer&gt; m_bufferedDataForCache;
</span><span class="cx">     std::unique_ptr&lt;NetworkCache::Entry&gt; m_cacheEntryForValidation;
</span><del>-
-    WebCore::RedirectChainCacheStatus m_redirectChainCacheStatus;
</del><ins>+    bool m_isWaitingContinueWillSendRequestForCachedRedirect { false };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -220,7 +220,7 @@
</span><span class="cx"> {
</span><span class="cx">     // The request is conditional so we force revalidation from the network. We merely check the disk cache
</span><span class="cx">     // so we can update the cache entry.
</span><del>-    if (request.isConditional())
</del><ins>+    if (request.isConditional() &amp;&amp; !entry.redirectRequest())
</ins><span class="cx">         return UseDecision::Validate;
</span><span class="cx"> 
</span><span class="cx">     if (!verifyVaryingRequestHeaders(entry.varyingRequestHeaders(), request))
</span><span class="lines">@@ -236,7 +236,7 @@
</span><span class="cx">     if (!entry.response().hasCacheValidatorFields())
</span><span class="cx">         return UseDecision::NoDueToMissingValidatorFields;
</span><span class="cx"> 
</span><del>-    return UseDecision::Validate;
</del><ins>+    return entry.redirectRequest() ? UseDecision::NoDueToExpiredRedirect : UseDecision::Validate;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static RetrieveDecision makeRetrieveDecision(const WebCore::ResourceRequest&amp; request)
</span><span class="lines">@@ -343,35 +343,35 @@
</span><span class="cx">     return StoreDecision::Yes;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Cache::retrieve(const WebCore::ResourceRequest&amp; originalRequest, const GlobalFrameID&amp; frameID, std::function&lt;void (std::unique_ptr&lt;Entry&gt;)&gt; completionHandler)
</del><ins>+void Cache::retrieve(const WebCore::ResourceRequest&amp; request, const GlobalFrameID&amp; frameID, std::function&lt;void (std::unique_ptr&lt;Entry&gt;)&gt; completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(isEnabled());
</span><del>-    ASSERT(originalRequest.url().protocolIsInHTTPFamily());
</del><ins>+    ASSERT(request.url().protocolIsInHTTPFamily());
</ins><span class="cx"> 
</span><del>-    LOG(NetworkCache, &quot;(NetworkProcess) retrieving %s priority %d&quot;, originalRequest.url().string().ascii().data(), static_cast&lt;int&gt;(originalRequest.priority()));
</del><ins>+    LOG(NetworkCache, &quot;(NetworkProcess) retrieving %s priority %d&quot;, request.url().string().ascii().data(), static_cast&lt;int&gt;(request.priority()));
</ins><span class="cx"> 
</span><span class="cx">     if (m_statistics)
</span><span class="cx">         m_statistics-&gt;recordRetrievalRequest(frameID.first);
</span><span class="cx"> 
</span><del>-    Key storageKey = makeCacheKey(originalRequest);
</del><ins>+    Key storageKey = makeCacheKey(request);
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
</span><span class="cx">     if (m_speculativeLoadManager)
</span><del>-        m_speculativeLoadManager-&gt;registerLoad(frameID, originalRequest, storageKey);
</del><ins>+        m_speculativeLoadManager-&gt;registerLoad(frameID, request, storageKey);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    auto retrieveDecision = makeRetrieveDecision(originalRequest);
</del><ins>+    auto retrieveDecision = makeRetrieveDecision(request);
</ins><span class="cx">     if (retrieveDecision != RetrieveDecision::Yes) {
</span><span class="cx">         if (m_statistics)
</span><del>-            m_statistics-&gt;recordNotUsingCacheForRequest(frameID.first, storageKey, originalRequest, retrieveDecision);
</del><ins>+            m_statistics-&gt;recordNotUsingCacheForRequest(frameID.first, storageKey, request, retrieveDecision);
</ins><span class="cx"> 
</span><span class="cx">         completionHandler(nullptr);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
</span><del>-    if (m_speculativeLoadManager &amp;&amp; m_speculativeLoadManager-&gt;retrieve(frameID, storageKey, [originalRequest, completionHandler](std::unique_ptr&lt;Entry&gt; entry) {
-        if (entry &amp;&amp; verifyVaryingRequestHeaders(entry-&gt;varyingRequestHeaders(), originalRequest))
</del><ins>+    if (m_speculativeLoadManager &amp;&amp; m_speculativeLoadManager-&gt;retrieve(frameID, storageKey, [request, completionHandler](std::unique_ptr&lt;Entry&gt; entry) {
+        if (entry &amp;&amp; verifyVaryingRequestHeaders(entry-&gt;varyingRequestHeaders(), request))
</ins><span class="cx">             completionHandler(WTF::move(entry));
</span><span class="cx">         else
</span><span class="cx">             completionHandler(nullptr);
</span><span class="lines">@@ -380,14 +380,14 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     auto startTime = std::chrono::system_clock::now();
</span><del>-    auto priority = static_cast&lt;unsigned&gt;(originalRequest.priority());
</del><ins>+    auto priority = static_cast&lt;unsigned&gt;(request.priority());
</ins><span class="cx"> 
</span><del>-    m_storage-&gt;retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, frameID](std::unique_ptr&lt;Storage::Record&gt; record) {
</del><ins>+    m_storage-&gt;retrieve(storageKey, priority, [this, request, completionHandler, startTime, storageKey, frameID](std::unique_ptr&lt;Storage::Record&gt; record) {
</ins><span class="cx">         if (!record) {
</span><span class="cx">             LOG(NetworkCache, &quot;(NetworkProcess) not found in storage&quot;);
</span><span class="cx"> 
</span><span class="cx">             if (m_statistics)
</span><del>-                m_statistics-&gt;recordRetrievalFailure(frameID.first, storageKey, originalRequest);
</del><ins>+                m_statistics-&gt;recordRetrievalFailure(frameID.first, storageKey, request);
</ins><span class="cx"> 
</span><span class="cx">             completionHandler(nullptr);
</span><span class="cx">             return false;
</span><span class="lines">@@ -397,7 +397,7 @@
</span><span class="cx"> 
</span><span class="cx">         auto entry = Entry::decodeStorageRecord(*record);
</span><span class="cx"> 
</span><del>-        auto useDecision = entry ? makeUseDecision(*entry, originalRequest) : UseDecision::NoDueToDecodeFailure;
</del><ins>+        auto useDecision = entry ? makeUseDecision(*entry, request) : UseDecision::NoDueToDecodeFailure;
</ins><span class="cx">         switch (useDecision) {
</span><span class="cx">         case UseDecision::Use:
</span><span class="cx">             break;
</span><span class="lines">@@ -410,34 +410,27 @@
</span><span class="cx"> 
</span><span class="cx"> #if !LOG_DISABLED
</span><span class="cx">         auto elapsedMS = static_cast&lt;int64_t&gt;(std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(std::chrono::system_clock::now() - startTime).count());
</span><del>-        LOG(NetworkCache, &quot;(NetworkProcess) retrieve complete useDecision=%d priority=%d time=%&quot; PRIi64 &quot;ms&quot;, static_cast&lt;int&gt;(useDecision), static_cast&lt;int&gt;(originalRequest.priority()), elapsedMS);
</del><ins>+        LOG(NetworkCache, &quot;(NetworkProcess) retrieve complete useDecision=%d priority=%d time=%&quot; PRIi64 &quot;ms&quot;, static_cast&lt;int&gt;(useDecision), static_cast&lt;int&gt;(request.priority()), elapsedMS);
</ins><span class="cx"> #endif
</span><span class="cx">         completionHandler(WTF::move(entry));
</span><span class="cx"> 
</span><span class="cx">         if (m_statistics)
</span><del>-            m_statistics-&gt;recordRetrievedCachedEntry(frameID.first, storageKey, originalRequest, useDecision);
</del><ins>+            m_statistics-&gt;recordRetrievedCachedEntry(frameID.first, storageKey, request, useDecision);
</ins><span class="cx">         return useDecision != UseDecision::NoDueToDecodeFailure;
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-std::unique_ptr&lt;Entry&gt; Cache::store(const WebCore::ResourceRequest&amp; originalRequest, const WebCore::ResourceResponse&amp; response, RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp; responseData, std::function&lt;void (MappedBody&amp;)&gt; completionHandler)
</del><ins>+std::unique_ptr&lt;Entry&gt; Cache::store(const WebCore::ResourceRequest&amp; request, const WebCore::ResourceResponse&amp; response, RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp; responseData, std::function&lt;void (MappedBody&amp;)&gt; completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(isEnabled());
</span><span class="cx">     ASSERT(responseData);
</span><span class="cx"> 
</span><del>-#if !LOG_DISABLED
-#if ENABLE(CACHE_PARTITIONING)
-    CString partition = originalRequest.cachePartition().latin1();
-#else
-    CString partition = &quot;No partition&quot;;
-#endif
-    LOG(NetworkCache, &quot;(NetworkProcess) storing %s, partition %s&quot;, originalRequest.url().string().latin1().data(), partition.data());
-#endif // !LOG_DISABLED
</del><ins>+    LOG(NetworkCache, &quot;(NetworkProcess) storing %s, partition %s&quot;, request.url().string().latin1().data(), makeCacheKey(request).partition().latin1().data());
</ins><span class="cx"> 
</span><del>-    StoreDecision storeDecision = makeStoreDecision(originalRequest, response);
</del><ins>+    StoreDecision storeDecision = makeStoreDecision(request, response);
</ins><span class="cx">     if (storeDecision != StoreDecision::Yes) {
</span><span class="cx">         LOG(NetworkCache, &quot;(NetworkProcess) didn't store, storeDecision=%d&quot;, static_cast&lt;int&gt;(storeDecision));
</span><del>-        auto key = makeCacheKey(originalRequest);
</del><ins>+        auto key = makeCacheKey(request);
</ins><span class="cx"> 
</span><span class="cx">         auto isSuccessfulRevalidation = response.httpStatusCode() == 304;
</span><span class="cx">         if (!isSuccessfulRevalidation) {
</span><span class="lines">@@ -451,7 +444,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    std::unique_ptr&lt;Entry&gt; cacheEntry = std::make_unique&lt;Entry&gt;(makeCacheKey(originalRequest), response, WTF::move(responseData), collectVaryingRequestHeaders(originalRequest, response));
</del><ins>+    std::unique_ptr&lt;Entry&gt; cacheEntry = std::make_unique&lt;Entry&gt;(makeCacheKey(request), response, WTF::move(responseData), collectVaryingRequestHeaders(request, response));
</ins><span class="cx"> 
</span><span class="cx">     auto record = cacheEntry-&gt;encodeAsStorageRecord();
</span><span class="cx"> 
</span><span class="lines">@@ -471,6 +464,31 @@
</span><span class="cx">     return cacheEntry;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::unique_ptr&lt;Entry&gt; Cache::storeRedirect(const WebCore::ResourceRequest&amp; request, const WebCore::ResourceResponse&amp; response, const WebCore::ResourceRequest&amp; redirectRequest)
+{
+    ASSERT(isEnabled());
+
+    LOG(NetworkCache, &quot;(NetworkProcess) storing redirect %s -&gt; %s&quot;, request.url().string().latin1().data(), redirectRequest.url().string().latin1().data());
+
+    StoreDecision storeDecision = makeStoreDecision(request, response);
+    if (storeDecision != StoreDecision::Yes) {
+        LOG(NetworkCache, &quot;(NetworkProcess) didn't store redirect, storeDecision=%d&quot;, static_cast&lt;int&gt;(storeDecision));
+        auto key = makeCacheKey(request);
+        if (m_statistics)
+            m_statistics-&gt;recordNotCachingResponse(key, storeDecision);
+
+        return nullptr;
+    }
+
+    std::unique_ptr&lt;Entry&gt; cacheEntry = std::make_unique&lt;Entry&gt;(makeCacheKey(request), response, redirectRequest, collectVaryingRequestHeaders(request, response));
+
+    auto record = cacheEntry-&gt;encodeAsStorageRecord();
+
+    m_storage-&gt;store(record, nullptr);
+    
+    return cacheEntry;
+}
+
</ins><span class="cx"> std::unique_ptr&lt;Entry&gt; Cache::update(const WebCore::ResourceRequest&amp; originalRequest, const GlobalFrameID&amp; frameID, const Entry&amp; existingEntry, const WebCore::ResourceResponse&amp; validatingResponse)
</span><span class="cx"> {
</span><span class="cx">     LOG(NetworkCache, &quot;(NetworkProcess) updating %s&quot;, originalRequest.url().string().latin1().data());
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -82,6 +82,7 @@
</span><span class="cx">     NoDueToVaryingHeaderMismatch,
</span><span class="cx">     NoDueToMissingValidatorFields,
</span><span class="cx">     NoDueToDecodeFailure,
</span><ins>+    NoDueToExpiredRedirect,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> using GlobalFrameID = std::pair&lt;uint64_t /*webPageID*/, uint64_t /*webFrameID*/&gt;;
</span><span class="lines">@@ -104,6 +105,7 @@
</span><span class="cx">     // Completion handler may get called back synchronously on failure.
</span><span class="cx">     void retrieve(const WebCore::ResourceRequest&amp;, const GlobalFrameID&amp;, std::function&lt;void (std::unique_ptr&lt;Entry&gt;)&gt;);
</span><span class="cx">     std::unique_ptr&lt;Entry&gt; store(const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp;, std::function&lt;void (MappedBody&amp;)&gt;);
</span><ins>+    std::unique_ptr&lt;Entry&gt; storeRedirect(const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp;, const WebCore::ResourceRequest&amp; redirectRequest);
</ins><span class="cx">     std::unique_ptr&lt;Entry&gt; update(const WebCore::ResourceRequest&amp;, const GlobalFrameID&amp;, const Entry&amp;, const WebCore::ResourceResponse&amp; validatingResponse);
</span><span class="cx"> 
</span><span class="cx">     void traverse(std::function&lt;void (const Entry*)&gt;&amp;&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -49,6 +49,18 @@
</span><span class="cx">     ASSERT(m_key.type() == &quot;resource&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Entry::Entry(const Key&amp; key, const WebCore::ResourceResponse&amp; response, const WebCore::ResourceRequest&amp; redirectRequest, const Vector&lt;std::pair&lt;String, String&gt;&gt;&amp; varyingRequestHeaders)
+    : m_key(key)
+    , m_timeStamp(std::chrono::system_clock::now())
+    , m_response(response)
+    , m_varyingRequestHeaders(varyingRequestHeaders)
+    , m_redirectRequest(WebCore::ResourceRequest::adopt(redirectRequest.copyData())) // Don't include the underlying platform request object.
+{
+    ASSERT(m_key.type() == &quot;resource&quot;);
+    // Redirect body is not needed even if exists.
+    m_redirectRequest-&gt;setHTTPBody(nullptr);
+}
+
</ins><span class="cx"> Entry::Entry(const Entry&amp; other)
</span><span class="cx">     : m_key(other.m_key)
</span><span class="cx">     , m_timeStamp(other.m_timeStamp)
</span><span class="lines">@@ -77,6 +89,11 @@
</span><span class="cx">     if (hasVaryingRequestHeaders)
</span><span class="cx">         encoder &lt;&lt; m_varyingRequestHeaders;
</span><span class="cx"> 
</span><ins>+    bool isRedirect = !!m_redirectRequest;
+    encoder &lt;&lt; isRedirect;
+    if (isRedirect)
+        m_redirectRequest-&gt;encodeWithoutPlatformData(encoder);
+
</ins><span class="cx">     encoder.encodeChecksum();
</span><span class="cx"> 
</span><span class="cx">     Data header(encoder.buffer(), encoder.bufferSize());
</span><span class="lines">@@ -105,6 +122,16 @@
</span><span class="cx">             return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    bool isRedirect;
+    if (!decoder.decode(isRedirect))
+        return nullptr;
+
+    if (isRedirect) {
+        entry-&gt;m_redirectRequest = std::make_unique&lt;WebCore::ResourceRequest&gt;();
+        if (!entry-&gt;m_redirectRequest-&gt;decodeWithoutPlatformData(decoder))
+            return nullptr;
+    }
+
</ins><span class="cx">     if (!decoder.verifyChecksum()) {
</span><span class="cx">         LOG(NetworkCache, &quot;(NetworkProcess) checksum verification failure\n&quot;);
</span><span class="cx">         return nullptr;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -30,12 +30,12 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;NetworkCacheStorage.h&quot;
</span><span class="cx"> #include &quot;ShareableResource.h&quot;
</span><ins>+#include &lt;WebCore/ResourceRequest.h&gt;
</ins><span class="cx"> #include &lt;WebCore/ResourceResponse.h&gt;
</span><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><del>-class ResourceRequest;
</del><span class="cx"> class SharedBuffer;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx">     Entry(const Key&amp;, const WebCore::ResourceResponse&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp;, const Vector&lt;std::pair&lt;String, String&gt;&gt;&amp; varyingRequestHeaders);
</span><ins>+    Entry(const Key&amp;, const WebCore::ResourceResponse&amp;, const WebCore::ResourceRequest&amp; redirectRequest, const Vector&lt;std::pair&lt;String, String&gt;&gt;&amp; varyingRequestHeaders);
</ins><span class="cx">     explicit Entry(const Storage::Record&amp;);
</span><span class="cx">     Entry(const Entry&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -58,6 +59,8 @@
</span><span class="cx">     const Vector&lt;std::pair&lt;String, String&gt;&gt;&amp; varyingRequestHeaders() const { return m_varyingRequestHeaders; }
</span><span class="cx"> 
</span><span class="cx">     WebCore::SharedBuffer* buffer() const;
</span><ins>+    const WebCore::ResourceRequest* redirectRequest() const { return m_redirectRequest.get(); }
+
</ins><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="cx">     ShareableResource::Handle&amp; shareableResourceHandle() const;
</span><span class="cx"> #endif
</span><span class="lines">@@ -80,6 +83,7 @@
</span><span class="cx">     WebCore::ResourceResponse m_response;
</span><span class="cx">     Vector&lt;std::pair&lt;String, String&gt;&gt; m_varyingRequestHeaders;
</span><span class="cx"> 
</span><ins>+    std::unique_ptr&lt;WebCore::ResourceRequest&gt; m_redirectRequest;
</ins><span class="cx">     mutable RefPtr&lt;WebCore::SharedBuffer&gt; m_buffer;
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="cx">     mutable ShareableResource::Handle m_shareableResourceHandle;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx">     ASSERT(!m_networkLoad);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SpeculativeLoad::willSendRedirectedRequest(const ResourceRequest&amp; request, const ResourceResponse&amp; redirectResponse)
</del><ins>+void SpeculativeLoad::willSendRedirectedRequest(const ResourceRequest&amp; request, const ResourceRequest&amp; redirectRequest, const ResourceResponse&amp; redirectResponse)
</ins><span class="cx"> {
</span><span class="cx">     updateRedirectChainStatus(m_redirectChainCacheStatus, redirectResponse);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -54,7 +54,7 @@
</span><span class="cx">     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override { }
</span><span class="cx">     virtual void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&amp;) override { }
</span><span class="cx">     virtual bool isSynchronous() const override { return false; }
</span><del>-    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceResponse&amp; redirectResponse) override;
</del><ins>+    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&amp;, const WebCore::ResourceRequest&amp; redirectRequest, const WebCore::ResourceResponse&amp; redirectResponse) override;
</ins><span class="cx">     virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&amp;) override;
</span><span class="cx">     virtual void didReceiveBuffer(RefPtr&lt;WebCore::SharedBuffer&gt;&amp;&amp;, int reportedEncodedDataLength) override;
</span><span class="cx">     virtual void didFinishLoading(double finishTime) override;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp (194312 => 194313)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp        2015-12-19 09:01:00 UTC (rev 194312)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp        2015-12-19 13:26:38 UTC (rev 194313)
</span><span class="lines">@@ -280,6 +280,7 @@
</span><span class="cx">     case UseDecision::NoDueToMissingValidatorFields:
</span><span class="cx">         return WebCore::DiagnosticLoggingKeys::missingValidatorFieldsKey();
</span><span class="cx">     case UseDecision::NoDueToDecodeFailure:
</span><ins>+    case UseDecision::NoDueToExpiredRedirect:
</ins><span class="cx">         return WebCore::DiagnosticLoggingKeys::otherKey();
</span><span class="cx">     case UseDecision::Use:
</span><span class="cx">     case UseDecision::Validate:
</span></span></pre>
</div>
</div>

</body>
</html>