Title: [200394] trunk/Source
Revision
200394
Author
cdu...@apple.com
Date
2016-05-03 16:26:03 -0700 (Tue, 03 May 2016)

Log Message

[WK2][DiskCache] Store common HTTP header names as strings
https://bugs.webkit.org/show_bug.cgi?id=157326
<rdar://problem/26073498>

Reviewed by Antti Koivisto.

Store common HTTP header names as strings in the disk cache instead of
using their value in the HTTPHeaderName enumeration. Having the disk
cache rely in the HTTPHeaderName enumeration is risky becomes it means
the cached data would become invalid every time someone updates
HTTPHeaderNames.in in WebCore. If someone were to update
HTTPHeaderNames.in without bumping the disk cache version, we would end
up with wrongly recognized HTTP header names after loading responses
from the cache.

* NetworkProcess/cache/NetworkCacheCoders.cpp:
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode):
(WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode):
* NetworkProcess/cache/NetworkCacheCoders.h:
* NetworkProcess/cache/NetworkCacheStorage.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/platform/network/HTTPHeaderMap.h (200393 => 200394)


--- trunk/Source/WebCore/platform/network/HTTPHeaderMap.h	2016-05-03 23:25:30 UTC (rev 200393)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderMap.h	2016-05-03 23:26:03 UTC (rev 200394)
@@ -138,7 +138,7 @@
 
     WEBCORE_EXPORT String get(const String& name) const;
     WEBCORE_EXPORT void set(const String& name, const String& value);
-    void add(const String& name, const String& value);
+    WEBCORE_EXPORT void add(const String& name, const String& value);
     WEBCORE_EXPORT bool contains(const String&) const;
     bool remove(const String&);
 

Modified: trunk/Source/WebKit2/ChangeLog (200393 => 200394)


--- trunk/Source/WebKit2/ChangeLog	2016-05-03 23:25:30 UTC (rev 200393)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-03 23:26:03 UTC (rev 200394)
@@ -1,3 +1,26 @@
+2016-05-03  Chris Dumez  <cdu...@apple.com>
+
+        [WK2][DiskCache] Store common HTTP header names as strings
+        https://bugs.webkit.org/show_bug.cgi?id=157326
+        <rdar://problem/26073498>
+
+        Reviewed by Antti Koivisto.
+
+        Store common HTTP header names as strings in the disk cache instead of
+        using their value in the HTTPHeaderName enumeration. Having the disk
+        cache rely in the HTTPHeaderName enumeration is risky becomes it means
+        the cached data would become invalid every time someone updates
+        HTTPHeaderNames.in in WebCore. If someone were to update
+        HTTPHeaderNames.in without bumping the disk cache version, we would end
+        up with wrongly recognized HTTP header names after loading responses
+        from the cache.
+
+        * NetworkProcess/cache/NetworkCacheCoders.cpp:
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::encode):
+        (WebKit::NetworkCache::Coder<WebCore::HTTPHeaderMap>::decode):
+        * NetworkProcess/cache/NetworkCacheCoders.h:
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+
 2016-05-03  Daniel Bates  <daba...@apple.com>
 
         Temporary workaround for Apple Internal builds

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp (200393 => 200394)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp	2016-05-03 23:25:30 UTC (rev 200393)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.cpp	2016-05-03 23:26:03 UTC (rev 200394)
@@ -190,7 +190,35 @@
     return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
 }
 
+// Store common HTTP headers as strings instead of using their value in the HTTPHeaderName enumeration
+// so that the headers stored in the cache stays valid even after HTTPHeaderName.in gets updated.
+void Coder<WebCore::HTTPHeaderMap>::encode(Encoder& encoder, const WebCore::HTTPHeaderMap& headers)
+{
+    encoder << static_cast<uint64_t>(headers.size());
+    for (auto& keyValue : headers) {
+        encoder << keyValue.key;
+        encoder << keyValue.value;
+    }
 }
+
+bool Coder<WebCore::HTTPHeaderMap>::decode(Decoder& decoder, WebCore::HTTPHeaderMap& headers)
+{
+    uint64_t headersSize;
+    if (!decoder.decode(headersSize))
+        return false;
+    for (uint64_t i = 0; i < headersSize; ++i) {
+        String name;
+        if (!decoder.decode(name))
+            return false;
+        String value;
+        if (!decoder.decode(value))
+            return false;
+        headers.add(name, value);
+    }
+    return true;
 }
 
+}
+}
+
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h (200393 => 200394)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h	2016-05-03 23:25:30 UTC (rev 200393)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheCoders.h	2016-05-03 23:26:03 UTC (rev 200394)
@@ -31,6 +31,7 @@
 #include "NetworkCacheDecoder.h"
 #include "NetworkCacheEncoder.h"
 #include <WebCore/CertificateInfo.h>
+#include <WebCore/HTTPHeaderMap.h>
 #include <WebCore/URL.h>
 #include <utility>
 #include <wtf/Forward.h>
@@ -264,6 +265,11 @@
     static bool decode(Decoder&, SHA1::Digest&);
 };
 
+template<> struct Coder<WebCore::HTTPHeaderMap> {
+    static void encode(Encoder&, const WebCore::HTTPHeaderMap&);
+    static bool decode(Decoder&, WebCore::HTTPHeaderMap&);
+};
+
 }
 }
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (200393 => 200394)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-05-03 23:25:30 UTC (rev 200393)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-05-03 23:26:03 UTC (rev 200394)
@@ -86,7 +86,7 @@
     size_t capacity() const { return m_capacity; }
     size_t approximateSize() const;
 
-    static const unsigned version = 6;
+    static const unsigned version = 7;
 
     String basePath() const;
     String versionPath() const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to