diff options
author | ricea <ricea@chromium.org> | 2014-10-07 20:37:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-08 03:37:20 +0000 |
commit | 64c07d7959386d30a0e4aa1371e2bdcd3d436476 (patch) | |
tree | fae68bfb988c022701b0ca6bc16431cf0e57c2d2 /net/http/http_response_headers_unittest.cc | |
parent | b3115e6252af69ca0aca60ed8b1334d46561b2b7 (diff) | |
download | chromium_src-64c07d7959386d30a0e4aa1371e2bdcd3d436476.zip chromium_src-64c07d7959386d30a0e4aa1371e2bdcd3d436476.tar.gz chromium_src-64c07d7959386d30a0e4aa1371e2bdcd3d436476.tar.bz2 |
stale-while-revalidate experimental implementation.
Simplistic implementation of stale-while-revalidate. See design doc at
https://docs.google.com/document/d/1DMCIMAKjyKeYiu69jlI5OsO2pGyAMb81XflYK4hxsNM/edit?usp=sharing
This implementation has known flaws:
1. Set-Cookie, Strict-Transport-Security and Public-Key-Pins headers
are lost from the responses of asynchronous revalidations.
2. Conditional requests sent from the Blink cache do not have the
stale-while-revalidate logic applied to them.
3. Support for the bandwidth reduction proxy is hacky.
It will be replaced with a better implementation if/when the concept is proven.
BUG=348877
TEST=net_unittests
Review URL: https://codereview.chromium.org/455623003
Cr-Commit-Position: refs/heads/master@{#298649}
Diffstat (limited to 'net/http/http_response_headers_unittest.cc')
-rw-r--r-- | net/http/http_response_headers_unittest.cc | 106 |
1 files changed, 82 insertions, 24 deletions
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index 098ce73e9..c0e8598 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -777,9 +777,14 @@ INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, ContentTypeTest, testing::ValuesIn(mimetype_tests)); +using net::ValidationType; +using net::VALIDATION_NONE; +using net::VALIDATION_SYNCHRONOUS; +using net::VALIDATION_ASYNCHRONOUS; + struct RequiresValidationTestData { const char* headers; - bool requires_validation; + ValidationType validation_type; }; class RequiresValidationTest @@ -800,41 +805,41 @@ TEST_P(RequiresValidationTest, RequiresValidation) { scoped_refptr<net::HttpResponseHeaders> parsed( new net::HttpResponseHeaders(headers)); - bool requires_validation = + ValidationType validation_type = parsed->RequiresValidation(request_time, response_time, current_time); - EXPECT_EQ(test.requires_validation, requires_validation); + EXPECT_EQ(test.validation_type, validation_type); } const struct RequiresValidationTestData requires_validation_tests[] = { // No expiry info: expires immediately. { "HTTP/1.1 200 OK\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // No expiry info: expires immediately. { "HTTP/1.1 200 OK\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Valid for a little while. { "HTTP/1.1 200 OK\n" "cache-control: max-age=10000\n" "\n", - false + VALIDATION_NONE }, // Expires in the future. { "HTTP/1.1 200 OK\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "expires: Wed, 28 Nov 2007 01:00:00 GMT\n" "\n", - false + VALIDATION_NONE }, // Already expired. { "HTTP/1.1 200 OK\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Max-age trumps expires. { "HTTP/1.1 200 OK\n" @@ -842,77 +847,77 @@ const struct RequiresValidationTestData requires_validation_tests[] = { "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" "cache-control: max-age=10000\n" "\n", - false + VALIDATION_NONE }, // Last-modified heuristic: modified a while ago. { "HTTP/1.1 200 OK\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" "\n", - false + VALIDATION_NONE }, { "HTTP/1.1 203 Non-Authoritative Information\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" "\n", - false + VALIDATION_NONE }, { "HTTP/1.1 206 Partial Content\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" "\n", - false + VALIDATION_NONE }, // Last-modified heuristic: modified recently. { "HTTP/1.1 200 OK\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" "\n", - true + VALIDATION_SYNCHRONOUS }, { "HTTP/1.1 203 Non-Authoritative Information\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" "\n", - true + VALIDATION_SYNCHRONOUS }, { "HTTP/1.1 206 Partial Content\n" "date: Wed, 28 Nov 2007 00:40:11 GMT\n" "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Cached permanent redirect. { "HTTP/1.1 301 Moved Permanently\n" "\n", - false + VALIDATION_NONE }, // Another cached permanent redirect. { "HTTP/1.1 308 Permanent Redirect\n" "\n", - false + VALIDATION_NONE }, // Cached redirect: not reusable even though by default it would be. { "HTTP/1.1 300 Multiple Choices\n" "Cache-Control: no-cache\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Cached forever by default. { "HTTP/1.1 410 Gone\n" "\n", - false + VALIDATION_NONE }, // Cached temporary redirect: not reusable. { "HTTP/1.1 302 Found\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Cached temporary redirect: reusable. { "HTTP/1.1 302 Found\n" "cache-control: max-age=10000\n" "\n", - false + VALIDATION_NONE }, // Cache-control: max-age=N overrides expires: date in the past. { "HTTP/1.1 200 OK\n" @@ -920,7 +925,7 @@ const struct RequiresValidationTestData requires_validation_tests[] = { "expires: Wed, 28 Nov 2007 00:20:11 GMT\n" "cache-control: max-age=10000\n" "\n", - false + VALIDATION_NONE }, // Cache-control: no-store overrides expires: in the future. { "HTTP/1.1 200 OK\n" @@ -928,7 +933,7 @@ const struct RequiresValidationTestData requires_validation_tests[] = { "expires: Wed, 29 Nov 2007 00:40:11 GMT\n" "cache-control: no-store,private,no-cache=\"foo\"\n" "\n", - true + VALIDATION_SYNCHRONOUS }, // Pragma: no-cache overrides last-modified heuristic. { "HTTP/1.1 200 OK\n" @@ -936,7 +941,60 @@ const struct RequiresValidationTestData requires_validation_tests[] = { "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" "pragma: no-cache\n" "\n", - true + VALIDATION_SYNCHRONOUS + }, + // max-age has expired, needs synchronous revalidation + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: max-age=300\n" + "\n", + VALIDATION_SYNCHRONOUS + }, + // max-age has expired, stale-while-revalidate has not, eligible for + // asynchronous revalidation + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: max-age=300, stale-while-revalidate=3600\n" + "\n", + VALIDATION_ASYNCHRONOUS + }, + // max-age and stale-while-revalidate have expired, needs synchronous + // revalidation + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: max-age=300, stale-while-revalidate=5\n" + "\n", + VALIDATION_SYNCHRONOUS + }, + // max-age is 0, stale-while-revalidate is large enough to permit + // asynchronous revalidation + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: max-age=0, stale-while-revalidate=360\n" + "\n", + VALIDATION_ASYNCHRONOUS + }, + // stale-while-revalidate must not override no-cache or similar directives. + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: no-cache, stale-while-revalidate=360\n" + "\n", + VALIDATION_SYNCHRONOUS + }, + // max-age has not expired, so no revalidation is needed. + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: max-age=3600, stale-while-revalidate=3600\n" + "\n", + VALIDATION_NONE + }, + // must-revalidate overrides stale-while-revalidate, so synchronous validation + // is needed. + { "HTTP/1.1 200 OK\n" + "date: Wed, 28 Nov 2007 00:40:11 GMT\n" + "cache-control: must-revalidate, max-age=300, stale-while-revalidate=3600\n" + "\n", + VALIDATION_SYNCHRONOUS }, // TODO(darin): Add many many more tests here. |