[WK2] Responses with 204 HTTP Status Code should be cacheable by default
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 23:46:03 +0000 (23:46 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 23:46:03 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143020
<rdar://problem/20281529>

Reviewed by Antti Koivisto.

Source/WebKit2:

Make responses with 204 HTTP Status Code cacheable by default, as
per RFC 7231:
http://tools.ietf.org/html/rfc7231#section-6.3.5

Test: http/tests/cache/disk-cache/disk-cache-204-status-code.html

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::canStore):

LayoutTests:

Add test to make sure that responses with 204 HTTP Status Code are
cacheable by default.

* http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt: Added.
* http/tests/cache/disk-cache/disk-cache-204-status-code.html: Added.
* http/tests/cache/disk-cache/resources/cache-test.js:
Re-introduce support for generating responses with only headers (no body).
This was mistakenly dropped when I rebased my patch for r181895.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181920 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html [new file with mode: 0644]
LayoutTests/http/tests/cache/disk-cache/disk-cache-validation-no-body.html
LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js
LayoutTests/http/tests/cache/disk-cache/resources/generate-response-no-body.cgi [deleted file]
LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp

index 898c135..71482dd 100644 (file)
@@ -1,3 +1,20 @@
+2015-03-24  Chris Dumez  <cdumez@apple.com>
+
+        [WK2] Responses with 204 HTTP Status Code should be cacheable by default
+        https://bugs.webkit.org/show_bug.cgi?id=143020
+        <rdar://problem/20281529>
+
+        Reviewed by Antti Koivisto.
+
+        Add test to make sure that responses with 204 HTTP Status Code are
+        cacheable by default.
+
+        * http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt: Added.
+        * http/tests/cache/disk-cache/disk-cache-204-status-code.html: Added.
+        * http/tests/cache/disk-cache/resources/cache-test.js:
+        Re-introduce support for generating responses with only headers (no body).
+        This was mistakenly dropped when I rebased my patch for r181895.
+
 2015-03-24  Beth Dakin  <bdakin@apple.com>
 
         Another attempted test fix after http://trac.webkit.org/changeset/181907
diff --git a/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt b/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code-expected.txt
new file mode 100644 (file)
index 0000000..623b424
--- /dev/null
@@ -0,0 +1,17 @@
+Test that responses with HTTP status code 204 are cacheable
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+running 2 tests
+
+response headers: {"Status":"204","Cache-control":"max-age=0"}
+response source: Network
+
+response headers: {"Status":"204","Cache-control":"max-age=100"}
+response source: Disk cache
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html b/LayoutTests/http/tests/cache/disk-cache/disk-cache-204-status-code.html
new file mode 100644 (file)
index 0000000..a7b76ff
--- /dev/null
@@ -0,0 +1,20 @@
+<script src="/js-test-resources/js-test-pre.js"></script>
+<script src="resources/cache-test.js"></script>
+<body>
+<script>
+
+var tests =
+[
+ { responseHeaders: {'Status': '204', 'Cache-control': 'max-age=0' }, includeBody: false },
+ { responseHeaders: {'Status': '204', 'Cache-control': 'max-age=100' }, includeBody: false },
+];
+
+description("Test that responses with HTTP status code 204 are cacheable");
+
+debug("running " + tests.length + " tests");
+debug("");
+
+runTests(tests);
+
+</script>
+<script src="/js-test-resources/js-test-post.js"></script>
index 606be19..53a04b6 100644 (file)
@@ -34,7 +34,7 @@ var testMatrix =
 
 description("Test permutations of various cache headers");
 
-var tests = generateTests(testMatrix, false /* withBody */);
+var tests = generateTests(testMatrix, false /* includeBody */);
 
 debug("running " + tests.length + " tests");
 debug("");
index d765dd8..314689b 100644 (file)
@@ -38,10 +38,12 @@ function makeHeaderValue(value)
     return value;
 }
 
-function generateTestURL(test)
+function generateTestURL(test, includeBody)
 {
+    includeBody = typeof includeBody !== 'undefined' ? includeBody : true;
     var uniqueTestId = Math.floor((Math.random() * 1000000000000));
-    var testURL = "resources/generate-response.cgi?uniqueId=" + uniqueTestId++ + "&Content-type=text/plain";
+    var cgi_script = "resources/generate-response.cgi?include-body=" + (includeBody ? "1" : "0");
+    var testURL = cgi_script + "&uniqueId=" + uniqueTestId++ + "&Content-type=text/plain";
     for (var header in test.responseHeaders)
         testURL += '&' + header + '=' + makeHeaderValue(test.responseHeaders[header]);
     return testURL;
@@ -50,7 +52,7 @@ function generateTestURL(test)
 function loadResource(test, onload)
 {
     if (!test.url)
-        test.url = generateTestURL(test);
+        test.url = generateTestURL(test, test.includeBody);
 
     test.xhr = new XMLHttpRequest();
     test.xhr.onload = onload;
@@ -115,8 +117,9 @@ function mergeFields(field, componentField)
     }
 }
 
-function generateTests(testMatrix)
+function generateTests(testMatrix, includeBody)
 {
+    includeBody = typeof includeBody !== 'undefined' ? includeBody : true;
     var tests = [];
 
     var testCount = 1;
@@ -138,6 +141,7 @@ function generateTests(testMatrix)
                 mergeFields(test[field], component[field]);
             }
         }
+        test.includeBody = includeBody;
         tests.push(test);
     }
     return tests;
diff --git a/LayoutTests/http/tests/cache/disk-cache/resources/generate-response-no-body.cgi b/LayoutTests/http/tests/cache/disk-cache/resources/generate-response-no-body.cgi
deleted file mode 100755 (executable)
index 6791f66..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl -w
-
-use CGI;
-use HTTP::Date;
-
-my $query = new CGI;
-@names = $query->param;
-
-if ($query->http && $query->http("If-None-Match") eq "match") {
-    print "Status: 304\n";
-}
-
-foreach (@names) {
-    next if ($_ eq "uniqueId");
-    print $_ . ": " . $query->param($_) . "\n";
-}
-print "\n";
index 919fb5e..ca05fbf 100755 (executable)
@@ -5,6 +5,7 @@ use HTTP::Date;
 
 my $query = new CGI;
 @names = $query->param;
+my $includeBody = $query->param('include-body') || 0;
 
 my $hasStatusCode = 0;
 if ($query->http && $query->http("If-None-Match") eq "match") {
@@ -14,8 +15,9 @@ if ($query->http && $query->http("If-None-Match") eq "match") {
 
 foreach (@names) {
     next if ($_ eq "uniqueId");
+    next if ($_ eq "include-body");
     next if ($_ eq "Status" and $hasStatusCode);
     print $_ . ": " . $query->param($_) . "\n";
 }
 print "\n";
-print "test";
+print "test" if $includeBody;
index 3ecf9d9..897483a 100644 (file)
@@ -1,3 +1,20 @@
+2015-03-24  Chris Dumez  <cdumez@apple.com>
+
+        [WK2] Responses with 204 HTTP Status Code should be cacheable by default
+        https://bugs.webkit.org/show_bug.cgi?id=143020
+        <rdar://problem/20281529>
+
+        Reviewed by Antti Koivisto.
+
+        Make responses with 204 HTTP Status Code cacheable by default, as
+        per RFC 7231:
+        http://tools.ietf.org/html/rfc7231#section-6.3.5
+
+        Test: http/tests/cache/disk-cache/disk-cache-204-status-code.html
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::canStore):
+
 2015-03-24  Enrica Casucci  <enrica@apple.com>
 
         [iOS] Remove unused keyboard code in WKSelectPopover class.
index 1e0d30c..f99b2d9 100644 (file)
@@ -321,6 +321,7 @@ static StoreDecision canStore(const WebCore::ResourceRequest& originalRequest, c
     switch (response.httpStatusCode()) {
     case 200: // OK
     case 203: // Non-Authoritative Information
+    case 204: // No Content
     case 300: // Multiple Choices
     case 301: // Moved Permanently
     case 302: // Found