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