Title: [184690] trunk
Revision
184690
Author
[email protected]
Date
2015-05-20 19:09:14 -0700 (Wed, 20 May 2015)

Log Message

Enable disk cache for range requests
https://bugs.webkit.org/show_bug.cgi?id=144682

Patch by Marcos Chavarría Teijeiro <[email protected]> on 2015-05-20
Reviewed by Antti Koivisto.

Source/WebKit2:

Add Range header value to the network cache key constructor so we take
into account this value. The 206 response code is also marked to be cached.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::makeCacheKey):
(WebKit::NetworkCache::isStatusCodeCacheableByDefault):
* NetworkProcess/cache/NetworkCacheKey.cpp:
(WebKit::NetworkCache::Key::Key):
(WebKit::NetworkCache::Key::operator=):
(WebKit::NetworkCache::Key::computeHash):
(WebKit::NetworkCache::Key::operator==):
(WebKit::NetworkCache::Key::encode):
(WebKit::NetworkCache::Key::decode):
(WebKit::NetworkCache::Key::stringToHash): Deleted.
* NetworkProcess/cache/NetworkCacheKey.h:

LayoutTests:

* http/tests/cache/disk-cache/disk-cache-range-expected.txt: Added. Add Test.
* http/tests/cache/disk-cache/disk-cache-range.html: Added.
* http/tests/cache/disk-cache/resources/generate-response.cgi: Modify script to return 206 and 416 response codes if Range header is present.
* platform/gtk/TestExpectations: Remove failing test.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (184689 => 184690)


--- trunk/LayoutTests/ChangeLog	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/LayoutTests/ChangeLog	2015-05-21 02:09:14 UTC (rev 184690)
@@ -1,3 +1,15 @@
+2015-05-20  Marcos Chavarría Teijeiro  <[email protected]>
+
+        Enable disk cache for range requests
+        https://bugs.webkit.org/show_bug.cgi?id=144682
+
+        Reviewed by Antti Koivisto.
+
+        * http/tests/cache/disk-cache/disk-cache-range-expected.txt: Added. Add Test.
+        * http/tests/cache/disk-cache/disk-cache-range.html: Added.
+        * http/tests/cache/disk-cache/resources/generate-response.cgi: Modify script to return 206 and 416 response codes if Range header is present.
+        * platform/gtk/TestExpectations: Remove failing test.
+
 2015-05-20  Chris Fleizach  <[email protected]>
 
         AX: improve list heuristics (presentational use versus actual lists)

Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range-expected.txt (0 => 184690)


--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range-expected.txt	2015-05-21 02:09:14 UTC (rev 184690)
@@ -0,0 +1,33 @@
+Test that request with different Range header values work.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+response headers: {"Cache-control":"max-age=100"}
+response source: Disk cache
+response status: 200
+
+response headers: {"Cache-control":"max-age=0"}
+response source: Network
+response status: 200
+
+response headers: {"Cache-control":"max-age=100","Range":"bytes=2-4"}
+response source: Disk cache
+response status: 206
+
+response headers: {"Cache-control":"max-age=0","Range":"bytes=2-4"}
+response source: Network
+response status: 206
+
+response headers: {"Cache-control":"max-age=100","Range":"bytes=5-7"}
+response source: Network
+response status: 416
+
+response headers: {"Cache-control":"max-age=0","Range":"bytes=5-7"}
+response source: Network
+response status: 416
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range.html (0 => 184690)


--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-range.html	2015-05-21 02:09:14 UTC (rev 184690)
@@ -0,0 +1,44 @@
+<script src=""
+<script src=""
+<body>
+<script>
+
+ //Redefine printResults function to print also response status.
+function printResults(tests)
+{
+    for (var i = 0; i < tests.length; ++i) {
+        var test = tests[i];
+        debug("response headers: " + JSON.stringify(test.responseHeaders));
+        if (test.expiresInFutureIn304)
+            debug("response's 'Expires' header is overriden by future date in 304 response");
+        if (test.requestHeaders)
+            debug("request headers: " + JSON.stringify(test.requestHeaders));
+        responseSource = internals.xhrResponseSource(test.xhr);
+        debug("response source: " + responseSource);
+	debug("response status: " + test.xhr.status);
+        debug("");
+    }
+}
+
+
+var testMatrix =
+[
+    [
+	{ responseHeaders: {'Cache-control': 'max-age=100' } },
+	{ responseHeaders: {'Cache-control': 'max-age=0' } },
+    ],
+    [
+        { responseHeaders: {}},
+        { responseHeaders: {'Range': 'bytes=2-4' } },
+        { responseHeaders: {'Range': 'bytes=5-7' } },
+    ]
+];
+
+description("Test that request with different Range header values work.");
+
+var tests = generateTests(testMatrix);
+
+runTests(tests);
+
+</script>
+<script src=""

Modified: trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi (184689 => 184690)


--- trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/resources/generate-response.cgi	2015-05-21 02:09:14 UTC (rev 184690)
@@ -19,6 +19,17 @@
     }
 }
 
+if ($query->http && $query->param("Range") =~ /bytes=(\d+)-(\d+)/) {
+
+    if ($1 < 6 && $2 < 6) {
+        print "Status: 206\n";
+    } else {
+	print "Status: 416\n";
+    }
+
+    $hasStatusCode = 1;
+}
+
 foreach (@names) {
     next if ($_ eq "uniqueId");
     next if ($_ eq "include-body");

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (184689 => 184690)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2015-05-21 02:09:14 UTC (rev 184690)
@@ -2292,8 +2292,6 @@
 
 webkit.org/b/144763 fast/events/scroll-in-scaled-page-with-overflow-hidden.html
 
-webkit.org/b/144682 http/tests/xmlhttprequest/range-test.html [ Failure ]
-
 webkit.org/b/141835 media/video-controls-no-scripting.html [ Failure ]
 webkit.org/b/145048 http/tests/misc/bad-charset-alias.html [ Failure ]
 webkit.org/b/145049 fast/text/simple-line-layout-text-stroke-width.html [ Failure ]

Modified: trunk/Source/WebKit2/ChangeLog (184689 => 184690)


--- trunk/Source/WebKit2/ChangeLog	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/Source/WebKit2/ChangeLog	2015-05-21 02:09:14 UTC (rev 184690)
@@ -1,3 +1,26 @@
+2015-05-20  Marcos Chavarría Teijeiro  <[email protected]>
+
+        Enable disk cache for range requests
+        https://bugs.webkit.org/show_bug.cgi?id=144682
+
+        Reviewed by Antti Koivisto.
+
+        Add Range header value to the network cache key constructor so we take
+        into account this value. The 206 response code is also marked to be cached.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::makeCacheKey):
+        (WebKit::NetworkCache::isStatusCodeCacheableByDefault):
+        * NetworkProcess/cache/NetworkCacheKey.cpp:
+        (WebKit::NetworkCache::Key::Key):
+        (WebKit::NetworkCache::Key::operator=):
+        (WebKit::NetworkCache::Key::computeHash):
+        (WebKit::NetworkCache::Key::operator==):
+        (WebKit::NetworkCache::Key::encode):
+        (WebKit::NetworkCache::Key::decode):
+        (WebKit::NetworkCache::Key::stringToHash): Deleted.
+        * NetworkProcess/cache/NetworkCacheKey.h:
+
 2015-05-20  Anders Carlsson  <[email protected]>
 
         WKWebsiteDataStore API doesn't report webkit.org as using Databases or App Cache after visiting http://www.webkit.org/demos/sticky-notes/

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (184689 => 184690)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-05-21 02:09:14 UTC (rev 184690)
@@ -109,7 +109,11 @@
 #endif
     if (partition.isEmpty())
         partition = ASCIILiteral("No partition");
-    return { request.httpMethod(), partition, request.url().string()  };
+
+    // FIXME: This implements minimal Range header disk cache support. We don't parse
+    // ranges so only the same exact range request will be served from the cache.
+    String range = request.httpHeaderField(WebCore::HTTPHeaderName::Range);
+    return { request.httpMethod(), partition, range, request.url().string()  };
 }
 
 static String headerValueForVary(const WebCore::ResourceRequest& request, const String& headerName)
@@ -237,6 +241,7 @@
     case 200: // OK
     case 203: // Non-Authoritative Information
     case 204: // No Content
+    case 206: // Partial Content
     case 300: // Multiple Choices
     case 301: // Moved Permanently
     case 404: // Not Found

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp (184689 => 184690)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2015-05-21 02:09:14 UTC (rev 184690)
@@ -40,14 +40,16 @@
     : m_method(o.m_method.isolatedCopy())
     , m_partition(o.m_partition.isolatedCopy())
     , m_identifier(o.m_identifier.isolatedCopy())
+    , m_range(o.m_range.isolatedCopy())
     , m_hash(o.m_hash)
 {
 }
 
-Key::Key(const String& method, const String& partition, const String& identifier)
+Key::Key(const String& method, const String& partition, const String& range, const String& identifier)
     : m_method(method.isolatedCopy())
     , m_partition(partition.isolatedCopy())
     , m_identifier(identifier.isolatedCopy())
+    , m_range(range.isolatedCopy())
     , m_hash(computeHash())
 {
 }
@@ -57,6 +59,7 @@
     m_method = other.m_method.isolatedCopy();
     m_partition = other.m_partition.isolatedCopy();
     m_identifier = other.m_identifier.isolatedCopy();
+    m_range = other.m_range.isolatedCopy();
     m_hash = other.m_hash;
     return *this;
 }
@@ -64,6 +67,10 @@
 static void hashString(MD5& md5, const String& string)
 {
     const uint8_t zero = 0;
+
+    if (string.isNull())
+        return;
+
     if (string.is8Bit() && string.containsOnlyASCII()) {
         md5.addBytes(string.characters8(), string.length());
         md5.addBytes(&zero, 1);
@@ -82,6 +89,7 @@
     hashString(md5, m_method);
     hashString(md5, m_partition);
     hashString(md5, m_identifier);
+    hashString(md5, m_range);
     MD5::Digest hash;
     md5.checksum(hash);
     return hash;
@@ -121,7 +129,7 @@
 
 bool Key::operator==(const Key& other) const
 {
-    return m_hash == other.m_hash && m_method == other.m_method && m_partition == other.m_partition && m_identifier == other.m_identifier;
+    return m_hash == other.m_hash && m_method == other.m_method && m_partition == other.m_partition && m_identifier == other.m_identifier && m_range == other.m_range;
 }
 
 void Key::encode(Encoder& encoder) const
@@ -129,12 +137,13 @@
     encoder << m_method;
     encoder << m_partition;
     encoder << m_identifier;
+    encoder << m_range;
     encoder << m_hash;
 }
 
 bool Key::decode(Decoder& decoder, Key& key)
 {
-    return decoder.decode(key.m_method) && decoder.decode(key.m_partition) && decoder.decode(key.m_identifier) && decoder.decode(key.m_hash);
+    return decoder.decode(key.m_method) && decoder.decode(key.m_partition) && decoder.decode(key.m_identifier) && decoder.decode(key.m_range) && decoder.decode(key.m_hash);
 }
 
 }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h (184689 => 184690)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2015-05-21 01:37:58 UTC (rev 184689)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2015-05-21 02:09:14 UTC (rev 184690)
@@ -44,7 +44,7 @@
     Key() { }
     Key(const Key&);
     Key(Key&&) = default;
-    Key(const String& method, const String& partition, const String& identifier);
+    Key(const String& method, const String& partition, const String& range, const String& identifier);
 
     Key& operator=(const Key&);
     Key& operator=(Key&&) = default;
@@ -74,6 +74,7 @@
     String m_method;
     String m_partition;
     String m_identifier;
+    String m_range;
     HashType m_hash;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to