summaryrefslogtreecommitdiffstats
path: root/net/http/http_response_headers_unittest.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 01:13:36 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 01:13:36 +0000
commitdbd39fbe246f0234c3d583ac52c3d9351acc9393 (patch)
tree7f8e89e1a1b8a8fb8c6cfd2a569cc00c4d272ca7 /net/http/http_response_headers_unittest.cc
parent5cfae741680e577a27ad993fb7508c8c156ce331 (diff)
downloadchromium_src-dbd39fbe246f0234c3d583ac52c3d9351acc9393.zip
chromium_src-dbd39fbe246f0234c3d583ac52c3d9351acc9393.tar.gz
chromium_src-dbd39fbe246f0234c3d583ac52c3d9351acc9393.tar.bz2
Http cache: Avoid resuming (and keeping) truncated entries
if the server doesn't provide a strong validator. We require: - A strong etag or a strong last modified date. - The total Content length. - Lack of an explicit rejection of ranges (Accept-ranges: none) This aligns better with the conditions used by Firefox. BUG=30220, b/2329250 TEST=unittests Review URL: http://codereview.chromium.org/517043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_response_headers_unittest.cc')
-rw-r--r--net/http/http_response_headers_unittest.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc
index d2ff378..bea4f36 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -1427,6 +1427,60 @@ TEST(HttpResponseHeadersTest, IsKeepAlive) {
}
}
+TEST(HttpResponseHeadersTest, HasStrongValidators) {
+ const struct {
+ const char* headers;
+ bool expected_result;
+ } tests[] = {
+ { "HTTP/0.9 200 OK",
+ false
+ },
+ { "HTTP/0.9 200 OK\n"
+ "Date: Wed, 28 Nov 2007 01:40:10 GMT\n"
+ "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n"
+ "ETag: \"foo\"\n",
+ true
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Date: Wed, 28 Nov 2007 00:41:10 GMT\n"
+ "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n",
+ true
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Date: Wed, 28 Nov 2007 00:41:09 GMT\n"
+ "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n",
+ false
+ },
+ { "HTTP/1.1 200 OK\n"
+ "ETag: \"foo\"\n",
+ true
+ },
+ // This is not really a weak etag:
+ { "HTTP/1.1 200 OK\n"
+ "etag: \"w/foo\"\n",
+ true
+ },
+ // This is a weak etag:
+ { "HTTP/1.1 200 OK\n"
+ "etag: w/\"foo\"\n",
+ false
+ },
+ { "HTTP/1.1 200 OK\n"
+ "etag: W / \"foo\"\n",
+ false
+ }
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ string headers(tests[i].headers);
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed =
+ new HttpResponseHeaders(headers);
+
+ EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) <<
+ "Failed test case " << i;
+ }
+}
+
TEST(HttpResponseHeadersTest, GetStatusText) {
std::string headers("HTTP/1.1 404 Not Found");
HeadersToRaw(&headers);