Title: [182145] trunk
Revision
182145
Author
cdu...@apple.com
Date
2015-03-30 10:35:39 -0700 (Mon, 30 Mar 2015)

Log Message

[WK2][NetworkCache] Add support for "Cache-Control: max-stale" request header
https://bugs.webkit.org/show_bug.cgi?id=143159
<rdar://problem/20333296>

Reviewed by Antti Koivisto.

Source/WebCore:

Add support for "Cache-Control: max-stale" 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 "Cache-Control: max-stale" 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 "Cache-Control: max-stale" 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (182144 => 182145)


--- trunk/LayoutTests/ChangeLog	2015-03-30 17:01:45 UTC (rev 182144)
+++ trunk/LayoutTests/ChangeLog	2015-03-30 17:35:39 UTC (rev 182145)
@@ -1,3 +1,17 @@
+2015-03-30  Chris Dumez  <cdu...@apple.com>
+
+        [WK2][NetworkCache] Add support for "Cache-Control: max-stale" request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        <rdar://problem/20333296>
+
+        Reviewed by Antti Koivisto.
+
+        Add layout test to cover support for "Cache-Control: max-stale" 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.
+
 2015-03-30  Jer Noble  <jer.no...@apple.com>
 
         [iOS] When Web Audio is interrupted by a phone call, it cannot be restarted.

Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale-expected.txt (0 => 182145)


--- 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)
@@ -0,0 +1,155 @@
+Test for 'max-stale' request header
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+running 36 tests
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=0"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=0, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=0, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=0, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=0, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=100, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=100, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=100, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=100, max-age=0"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=0, max-age=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=0, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=0, max-age=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=0, max-age=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0"}
+request headers: {"Cache-control":"max-stale=100, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=100"}
+request headers: {"Cache-control":"max-stale=100, max-age=100"}
+response source: Disk cache
+
+response headers: {"Cache-control":"max-age=0","Age":"200"}
+request headers: {"Cache-control":"max-stale=100, max-age=100"}
+response source: Network
+
+response headers: {"Cache-control":"max-age=100","Age":"200"}
+request headers: {"Cache-control":"max-stale=100, max-age=100"}
+response source: Network
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-request-max-stale.html (0 => 182145)


--- 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)
@@ -0,0 +1,38 @@
+<script src=""
+<script src=""
+<body>
+<script>
+
+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("Test for 'max-stale' request header");
+
+var tests = generateTests(testMatrix);
+
+debug("running " + tests.length + " tests");
+debug("");
+
+runTests(tests);
+
+</script>
+<script src=""

Modified: trunk/Source/WebCore/ChangeLog (182144 => 182145)


--- 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)
@@ -1,3 +1,20 @@
+2015-03-30  Chris Dumez  <cdu...@apple.com>
+
+        [WK2][NetworkCache] Add support for "Cache-Control: max-stale" request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        <rdar://problem/20333296>
+
+        Reviewed by Antti Koivisto.
+
+        Add support for "Cache-Control: max-stale" 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:
+
 2015-03-30  Simon Fraser  <simon.fra...@apple.com>
 
         Fix iOS internal build after r182132.

Modified: trunk/Source/WebCore/platform/network/CacheValidation.cpp (182144 => 182145)


--- 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)
@@ -274,6 +274,21 @@
                 double maxAge = directives[i].second.toDouble(&ok);
                 if (ok)
                     result.maxAge = maxAge;
+            } else if (equalIgnoringCase(directives[i].first, "max-stale")) {
+                // 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<double>::max();
+                    continue;
+                }
+                bool ok;
+                double maxStale = directives[i].second.toDouble(&ok);
+                if (ok)
+                    result.maxStale = maxStale;
             }
         }
     }

Modified: trunk/Source/WebCore/platform/network/CacheValidation.h (182144 => 182145)


--- 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)
@@ -55,6 +55,7 @@
 
 struct CacheControlDirectives {
     double maxAge { std::numeric_limits<double>::quiet_NaN() };
+    double maxStale { std::numeric_limits<double>::quiet_NaN() };
     bool noCache { false };
     bool noStore { false };
     bool mustRevalidate { false };

Modified: trunk/Source/WebKit2/ChangeLog (182144 => 182145)


--- 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)
@@ -1,3 +1,19 @@
+2015-03-30  Chris Dumez  <cdu...@apple.com>
+
+        [WK2][NetworkCache] Add support for "Cache-Control: max-stale" request header
+        https://bugs.webkit.org/show_bug.cgi?id=143159
+        <rdar://problem/20333296>
+
+        Reviewed by Antti Koivisto.
+
+        Add support for "Cache-Control: max-stale" 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):
+
 2015-03-30  Csaba Osztrogonác  <o...@webkit.org>
 
         [EFL][GTK] WebKit2's generate-forwarding-headers.pl should fail if clashing headers found

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182144 => 182145)


--- 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)
@@ -150,7 +150,7 @@
     return false;
 }
 
-static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::milliseconds timestamp)
+static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::milliseconds timestamp, double maxStale)
 {
     if (response.cacheControlContainsNoCache())
         return true;
@@ -159,17 +159,18 @@
     double age = WebCore::computeCurrentAge(response, doubleTimeStamp.count());
     double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, doubleTimeStamp.count());
 
-    bool hasExpired = age > lifetime;
+    maxStale = std::isnan(maxStale) ? 0 : maxStale;
+    bool hasExpired = age - lifetime > maxStale;
 
 #ifndef LOG_DISABLED
     if (hasExpired)
-        LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasExpired age=%f lifetime=%f", age, lifetime);
+        LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasExpired age=%f lifetime=%f max-stale=%g", age, lifetime, maxStale);
 #endif
 
     return hasExpired;
 }
 
-static bool requestRequiresRevalidation(const WebCore::ResourceRequest& request)
+static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::chrono::milliseconds timestamp)
 {
     auto requestDirectives = WebCore::parseCacheControlDirectives(request.httpHeaderFields());
     if (requestDirectives.noCache)
@@ -178,7 +179,7 @@
     if (requestDirectives.maxAge == 0)
         return true;
 
-    return false;
+    return responseHasExpired(response, timestamp, requestDirectives.maxStale);
 }
 
 static UseDecision canUse(const Entry& entry, const WebCore::ResourceRequest& request)
@@ -192,8 +193,7 @@
     if (cachePolicyAllowsExpired(request.cachePolicy()))
         return UseDecision::Use;
 
-    bool needsRevalidation = requestRequiresRevalidation(request) || responseHasExpired(entry.response(), entry.timeStamp());
-    if (!needsRevalidation)
+    if (!responseNeedsRevalidation(entry.response(), request, entry.timeStamp()))
         return UseDecision::Use;
 
     bool hasValidatorFields = entry.response().hasCacheValidatorFields();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to