diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 21:57:35 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 21:57:35 +0000 |
commit | 39d4a0984353dd3698b44e411dc82423d8a7c33e (patch) | |
tree | b1f3d658bf726f7593b8865bf233387eed36dc92 /net/http | |
parent | 2a9f248416fa4d1d7c1f0e5830785db4d98a72b7 (diff) | |
download | chromium_src-39d4a0984353dd3698b44e411dc82423d8a7c33e.zip chromium_src-39d4a0984353dd3698b44e411dc82423d8a7c33e.tar.gz chromium_src-39d4a0984353dd3698b44e411dc82423d8a7c33e.tar.bz2 |
Http cache: Make sure that we don't use http 1.1 features
for http 1.0 resources.
BUG=74061
TEST=netunittests
Review URL: http://codereview.chromium.org/6995010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache_transaction.cc | 3 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 64 | ||||
-rw-r--r-- | net/http/http_response_headers.cc | 5 | ||||
-rw-r--r-- | net/http/http_response_headers_unittest.cc | 10 | ||||
-rw-r--r-- | net/http/partial_data.cc | 5 |
5 files changed, 79 insertions, 8 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index c8b2b33..9af0c83 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -1694,6 +1694,9 @@ bool HttpCache::Transaction::ConditionalizeRequest() { response_.headers->EnumerateHeader(NULL, "last-modified", &last_modified_value); + if (response_.headers->GetHttpVersion() < HttpVersion(1, 1)) + etag_value.clear(); + if (etag_value.empty() && last_modified_value.empty()) return false; diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index abc83db..c7a1ae6 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -948,7 +948,7 @@ const MockTransaction kRangeGET_TransactionOK = { EXTRA_HEADER, net::LOAD_NORMAL, "HTTP/1.1 206 Partial Content", - "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" + "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" "ETag: \"foo\"\n" "Accept-Ranges: bytes\n" "Content-Length: 10\n", @@ -2210,6 +2210,62 @@ TEST(HttpCache, ETagGET_ConditionalRequest_304) { EXPECT_EQ(1, cache.disk_cache()->create_count()); } +static void ETagGet_UnconditionalRequest_Handler( + const net::HttpRequestInfo* request, + std::string* response_status, + std::string* response_headers, + std::string* response_data) { + EXPECT_FALSE( + request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); +} + +TEST(HttpCache, ETagGET_Http10) { + MockHttpCache cache; + + ScopedMockTransaction transaction(kETagGET_Transaction); + transaction.status = "HTTP/1.0 200 OK"; + + // Write to the cache. + RunTransactionTest(cache.http_cache(), transaction); + + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(0, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + // Get the same URL again, without generating a conditional request. + transaction.load_flags = net::LOAD_VALIDATE_CACHE; + transaction.handler = ETagGet_UnconditionalRequest_Handler; + RunTransactionTest(cache.http_cache(), transaction); + + EXPECT_EQ(2, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); +} + +TEST(HttpCache, ETagGET_Http10_Range) { + MockHttpCache cache; + + ScopedMockTransaction transaction(kETagGET_Transaction); + transaction.status = "HTTP/1.0 200 OK"; + + // Write to the cache. + RunTransactionTest(cache.http_cache(), transaction); + + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(0, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + // Get the same URL again, but use a byte range request. + transaction.load_flags = net::LOAD_VALIDATE_CACHE; + transaction.handler = ETagGet_UnconditionalRequest_Handler; + transaction.request_headers = "Range: bytes = 5-"; + RunTransactionTest(cache.http_cache(), transaction); + + EXPECT_EQ(3, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(2, cache.disk_cache()->create_count()); +} + static void ETagGet_ConditionalRequest_NoStore_Handler( const net::HttpRequestInfo* request, std::string* response_status, @@ -4349,7 +4405,7 @@ TEST(HttpCache, GET_IncompleteResource) { AddMockTransaction(&kRangeGET_TransactionOK); std::string raw_headers("HTTP/1.1 200 OK\n" - "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" + "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" "ETag: \"foo\"\n" "Accept-Ranges: bytes\n" "Content-Length: 80\n"); @@ -4366,7 +4422,7 @@ TEST(HttpCache, GET_IncompleteResource) { // We update the headers with the ones received while revalidating. std::string expected_headers( "HTTP/1.1 200 OK\n" - "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" + "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" "Accept-Ranges: bytes\n" "ETag: \"foo\"\n" "Content-Length: 80\n"); @@ -4396,7 +4452,7 @@ TEST(HttpCache, GET_IncompleteResource2) { // Content-length will be intentionally bad. std::string raw_headers("HTTP/1.1 200 OK\n" - "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" + "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" "ETag: \"foo\"\n" "Accept-Ranges: bytes\n" "Content-Length: 50\n"); diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 5bf2beb..47047c9 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1076,6 +1076,9 @@ bool HttpResponseHeaders::IsKeepAlive() const { } bool HttpResponseHeaders::HasStrongValidators() const { + if (GetHttpVersion() < HttpVersion(1, 1)) + return false; + std::string etag_value; EnumerateHeader(NULL, "etag", &etag_value); if (!etag_value.empty()) { diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index 7c1f134..c2d34b4 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1434,7 +1434,13 @@ TEST(HttpResponseHeadersTest, HasStrongValidators) { { "HTTP/0.9 200 OK", false }, - { "HTTP/0.9 200 OK\n" + { "HTTP/1.0 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", + false + }, + { "HTTP/1.1 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", diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc index d76d689..f991a95 100644 --- a/net/http/partial_data.cc +++ b/net/http/partial_data.cc @@ -240,6 +240,9 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers, disk_cache::Entry* entry, bool truncated) { resource_size_ = 0; + if (!headers->HasStrongValidators()) + return false; + if (truncated) { DCHECK_EQ(headers->response_code(), 200); // We don't have the real length and the user may be trying to create a @@ -250,7 +253,7 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers, // Now we avoid resume if there is no content length, but that was not // always the case so double check here. int64 total_length = headers->GetContentLength(); - if (total_length <= 0 || !headers->HasStrongValidators()) + if (total_length <= 0) return false; truncated_ = true; |