We should not speculatively revalidate cached redirects
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Apr 2016 00:14:05 +0000 (00:14 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Apr 2016 00:14:05 +0000 (00:14 +0000)
commit0db80647c39f0d203678df011f35f0be690d34a5
treeb2930c0a7fcc7d37b0b7555479c2aabf8e2c9f85
parent51554f55fb7798425f49dab45a9305b6f32d8016
We should not speculatively revalidate cached redirects
https://bugs.webkit.org/show_bug.cgi?id=156548
<rdar://problem/25583886>

Reviewed by Darin Adler.

Source/WebKit2:

Stop speculatively revalidating cached redirects. This matches matches
the behavior in NetworkCache's makeUseDecision() which reuses cached
redirects only if they do not need revalidation.

This was breaking fonts.css loading on stripe.com because the
SpeculativeLoadManager would wrongly speculatively revalidate the
redirect and then serve a 302 response the NetworkResourceLoader
when the actual request came in. This would cause us to not follow
the redirect.

* NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::willSendRedirectedRequest):
Abort the speculative load if it hits a redirect. This is the safe thing
to do in this case, as we are supposed to do a hand-shake with WebCore
in such case.

(WebKit::NetworkCache::SpeculativeLoad::didReceiveResponse):
Let successful validations fall through instead of calling didComplete()
early. This matches what is not in NetworkResourceLoader. This way,
didFinishLoading() ends up getting called for both successful and
unsuccessful (i.e. did not return a 302 status code) network validation.

(WebKit::NetworkCache::SpeculativeLoad::didFinishLoading):
- Stop dealing with redirects as we abort the load as soon as we hit a
  redirect now.
- Stop asserting that m_cacheEntryForValidation is null now that this
  is called for successful validations as well.

(WebKit::NetworkCache::SpeculativeLoad::abort):
New method that aborts the network loads, calls the completion handler
and clean up. It is called in the case we hit a redirect while
revalidating.

* NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
Drop m_redirectChainCacheStatus member as we no longer deal with
redirects.

* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveEntryFromStorage):
If the resource needs revalidation AND is a cached redirect, then do not
use it. This matches what is done in NetworkCache's makeUseDecision().

Tools:

Re-enable speculative loading in the context of layout tests. This was
turned off by mistake when speculative loading was turned into a
setting recently.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::generatePageConfiguration):

LayoutTests:

Add layout test to make sure that speculative loading does not break
redirects. This replicates the issue seen with fonts.css on stripe.com.

* http/tests/cache/disk-cache/speculative-validation/cacheable-redirect-expected.txt: Added.
* http/tests/cache/disk-cache/speculative-validation/cacheable-redirect.html: Added.
* http/tests/cache/disk-cache/speculative-validation/resources/cacheable-redirect-frame.php: Added.
* http/tests/cache/disk-cache/speculative-validation/resources/css-to-revalidate.php: Added.
* http/tests/cache/disk-cache/speculative-validation/resources/redirect-to-css.php: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199521 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache/disk-cache/speculative-validation/cacheable-redirect-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/speculative-validation/cacheable-redirect.html [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/speculative-validation/resources/cacheable-redirect-frame.php [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/speculative-validation/resources/css-to-revalidate.php [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/speculative-validation/resources/redirect-to-css.php [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h
Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/TestController.cpp