summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 19:22:57 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 19:22:57 +0000
commitc14117b97d9fee1ec586c92898262900c2079eec (patch)
tree57009a89fa95464e57868c3c66187abef09e1e23 /net/http
parent4e416ed9896dcd44547332f366c2767eb1223aa2 (diff)
downloadchromium_src-c14117b97d9fee1ec586c92898262900c2079eec.zip
chromium_src-c14117b97d9fee1ec586c92898262900c2079eec.tar.gz
chromium_src-c14117b97d9fee1ec586c92898262900c2079eec.tar.bz2
Http cache: If we issue a byte range request for x bytes
and the server replies that it is giving us x bytes but we receive less than that, forward the failure to the caller instead of asking for another range. BUG=31000 TEST=unittests Review URL: http://codereview.chromium.org/545101 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36771 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache_transaction.cc8
-rw-r--r--net/http/http_cache_unittest.cc41
2 files changed, 47 insertions, 2 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 733b2e1..7c56627 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -1527,8 +1527,12 @@ int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
if (result < 0)
return result;
- if (partial_.get())
- return DoPartialNetworkReadCompleted(result);
+ if (partial_.get()) {
+ // This may be the last request.
+ if (!(result == 0 && !truncated_ &&
+ (partial_->IsLastRange() || mode_ == WRITE)))
+ return DoPartialNetworkReadCompleted(result);
+ }
if (result == 0) // End of file.
DoneWritingToEntry(true);
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 72231fb..764d1fd 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -3331,6 +3331,47 @@ TEST(HttpCache, RangeGET_FastFlakyServer) {
RemoveMockTransaction(&transaction);
}
+// Tests that when the server gives us less data than expected, we don't keep
+// asking for more data.
+TEST(HttpCache, RangeGET_FastFlakyServer2) {
+ MockHttpCache cache;
+ cache.http_cache()->set_enable_range_support(true);
+
+ // First, check with an empty cache (WRITE mode).
+ MockTransaction transaction(kRangeGET_TransactionOK);
+ transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER;
+ transaction.data = "rg: 40-"; // Less than expected.
+ transaction.handler = NULL;
+ std::string headers(transaction.response_headers);
+ headers.append("Content-Range: bytes 40-49/80\n");
+ transaction.response_headers = headers.c_str();
+
+ AddMockTransaction(&transaction);
+
+ // 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());
+
+ // Now verify that even in READ_WRITE mode, we forward the bad response to
+ // the caller.
+ transaction.request_headers = "Range: bytes = 60-69\r\n" EXTRA_HEADER;
+ transaction.data = "rg: 60-"; // Less than expected.
+ headers = kRangeGET_TransactionOK.response_headers;
+ headers.append("Content-Range: bytes 60-69/80\n");
+ transaction.response_headers = headers.c_str();
+
+ 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());
+
+ RemoveMockTransaction(&transaction);
+}
+
#ifdef NDEBUG
// This test hits a NOTREACHED so it is a release mode only test.
TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) {