Title: [188690] trunk
- Revision
- 188690
- Author
- [email protected]
- Date
- 2015-08-20 10:47:08 -0700 (Thu, 20 Aug 2015)
Log Message
[Cocoa] Treat Epoch as invalid value for "Last-Modified" header
https://bugs.webkit.org/show_bug.cgi?id=148162
rdar://problem/22330837
Reviewed by Antti Koivisto.
Source/WebCore:
Ignore "Last-Modified" header when computing heuristic freshness if it
is Epoch. CFNetwork currently converts a malformed date for Last-Modified
into Epoch so there is no way for us to distinguish Epoch from invalid
input. Without this, we would end up with cached resources that have a
giant lifetime (> 4 years) due to a malformed HTTP header.
Some Websites (e.g. www.popehat.com) also wrongly return Epoch as
Last-Modified value and we would end up caching it overly aggressively.
Now that we consider Epoch as an invalid value for Last-Modified, it will
also work around this content bug.
Test: http/tests/cache/disk-cache/disk-cache-last-modified.html
* platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::lastModified):
LayoutTests:
Add better layout test coverage for using the "Last-Modified" header to
compute heuristic freshness. In particular, it adds coverage for the
following values: Epoch, malformed date.
* http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt: Added.
* http/tests/cache/disk-cache/disk-cache-last-modified.html: Added.
New test.
* http/tests/cache/disk-cache/resources/cache-test.js:
(makeHeaderValue):
makeHeaderValue() was not resolving 'now(-1000)' into a date. This means that the
tests using it would end up sending an invalid "Last-Modified" header which our
networking code was translating to Epoch. We now ignore Epoch as Last-Modified
value for computing heuristic freshness to not cache due to malformed headers.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (188689 => 188690)
--- trunk/LayoutTests/ChangeLog 2015-08-20 17:41:43 UTC (rev 188689)
+++ trunk/LayoutTests/ChangeLog 2015-08-20 17:47:08 UTC (rev 188690)
@@ -1,3 +1,26 @@
+2015-08-20 Chris Dumez <[email protected]>
+
+ [Cocoa] Treat Epoch as invalid value for "Last-Modified" header
+ https://bugs.webkit.org/show_bug.cgi?id=148162
+ rdar://problem/22330837
+
+ Reviewed by Antti Koivisto.
+
+ Add better layout test coverage for using the "Last-Modified" header to
+ compute heuristic freshness. In particular, it adds coverage for the
+ following values: Epoch, malformed date.
+
+ * http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt: Added.
+ * http/tests/cache/disk-cache/disk-cache-last-modified.html: Added.
+ New test.
+
+ * http/tests/cache/disk-cache/resources/cache-test.js:
+ (makeHeaderValue):
+ makeHeaderValue() was not resolving 'now(-1000)' into a date. This means that the
+ tests using it would end up sending an invalid "Last-Modified" header which our
+ networking code was translating to Epoch. We now ignore Epoch as Last-Modified
+ value for computing heuristic freshness to not cache due to malformed headers.
+
2015-08-20 Eric Carlson <[email protected]>
Revert accidental commit of a new test that isn't ready for prime time.
Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt (0 => 188690)
--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt 2015-08-20 17:47:08 UTC (rev 188690)
@@ -0,0 +1,41 @@
+Covers uses of 'Last-Modified' header to compute heuristic freshness.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+running 3 tests
+
+--------Testing loads from disk cache--------
+response headers: {"Last-Modified":"Thu, 01 Jan 2000 00:00:00 GMT"}
+response source: Disk cache
+
+response headers: {"Last-Modified":"Thu, 01 Jan 1970 00:00:00 GMT"}
+response source: Network
+
+response headers: {"Last-Modified":"invalid"}
+response source: Network
+
+--------Testing loads through memory cache (XHR behavior)--------
+response headers: {"Last-Modified":"Thu, 01 Jan 2000 00:00:00 GMT"}
+response source: Memory cache
+
+response headers: {"Last-Modified":"Thu, 01 Jan 1970 00:00:00 GMT"}
+response source: Network
+
+response headers: {"Last-Modified":"invalid"}
+response source: Network
+
+--------Testing loads through memory cache (subresource behavior)--------
+response headers: {"Last-Modified":"Thu, 01 Jan 2000 00:00:00 GMT"}
+response source: Memory cache
+
+response headers: {"Last-Modified":"Thu, 01 Jan 1970 00:00:00 GMT"}
+response source: Network
+
+response headers: {"Last-Modified":"invalid"}
+response source: Network
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified.html (0 => 188690)
--- trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified.html (rev 0)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/disk-cache-last-modified.html 2015-08-20 17:47:08 UTC (rev 188690)
@@ -0,0 +1,21 @@
+<script src=""
+<script src=""
+<body>
+<script>
+
+var tests =
+[
+ { responseHeaders: {'Last-Modified': 'Thu, 01 Jan 2000 00:00:00 GMT' } }, // Heuristic freshness.
+ { responseHeaders: {'Last-Modified': 'Thu, 01 Jan 1970 00:00:00 GMT' } }, // Epoch.
+ { responseHeaders: {'Last-Modified': 'invalid' } }, // Invalid date
+];
+
+description("Covers uses of 'Last-Modified' header to compute heuristic freshness.");
+
+debug("running " + tests.length + " tests");
+debug("");
+
+runTests(tests);
+
+</script>
+<script src=""
Modified: trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js (188689 => 188690)
--- trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js 2015-08-20 17:41:43 UTC (rev 188689)
+++ trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js 2015-08-20 17:47:08 UTC (rev 188690)
@@ -33,6 +33,8 @@
return (new Date(new Date().getTime() + serverClientTimeDelta)).toUTCString();
if (value == 'now(100)')
return (new Date(new Date().getTime() + serverClientTimeDelta + 100 * 1000)).toUTCString();
+ if (value == 'now(-1000)')
+ return (new Date(new Date().getTime() - serverClientTimeDelta - 1000 * 1000)).toUTCString()
if (value == 'unique()')
return "" + uniqueIdCounter++;
return value;
Modified: trunk/Source/WebCore/ChangeLog (188689 => 188690)
--- trunk/Source/WebCore/ChangeLog 2015-08-20 17:41:43 UTC (rev 188689)
+++ trunk/Source/WebCore/ChangeLog 2015-08-20 17:47:08 UTC (rev 188690)
@@ -1,3 +1,27 @@
+2015-08-20 Chris Dumez <[email protected]>
+
+ [Cocoa] Treat Epoch as invalid value for "Last-Modified" header
+ https://bugs.webkit.org/show_bug.cgi?id=148162
+ rdar://problem/22330837
+
+ Reviewed by Antti Koivisto.
+
+ Ignore "Last-Modified" header when computing heuristic freshness if it
+ is Epoch. CFNetwork currently converts a malformed date for Last-Modified
+ into Epoch so there is no way for us to distinguish Epoch from invalid
+ input. Without this, we would end up with cached resources that have a
+ giant lifetime (> 4 years) due to a malformed HTTP header.
+
+ Some Websites (e.g. www.popehat.com) also wrongly return Epoch as
+ Last-Modified value and we would end up caching it overly aggressively.
+ Now that we consider Epoch as an invalid value for Last-Modified, it will
+ also work around this content bug.
+
+ Test: http/tests/cache/disk-cache/disk-cache-last-modified.html
+
+ * platform/network/ResourceResponseBase.cpp:
+ (WebCore::ResourceResponseBase::lastModified):
+
2015-08-19 Brian Burg <[email protected]>
Web Inspector: add TestHarness option to tee all commands to system console
Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp (188689 => 188690)
--- trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2015-08-20 17:41:43 UTC (rev 188689)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2015-08-20 17:47:08 UTC (rev 188690)
@@ -425,6 +425,13 @@
if (!m_haveParsedLastModifiedHeader) {
m_lastModified = parseDateValueInHeader(m_httpHeaderFields, HTTPHeaderName::LastModified);
+#if PLATFORM(COCOA)
+ // CFNetwork converts malformed dates into Epoch so we need to treat Epoch as
+ // an invalid value (rdar://problem/22352838).
+ const std::chrono::system_clock::time_point epoch;
+ if (m_lastModified && m_lastModified.value() == epoch)
+ m_lastModified = Nullopt;
+#endif
m_haveParsedLastModifiedHeader = true;
}
return m_lastModified;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes