summaryrefslogtreecommitdiffstats
path: root/net/http/partial_data.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 19:48:29 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 19:48:29 +0000
commitab80bac7428906fccfafbc4d620538ded23a2a83 (patch)
tree1d600ea2a46e92dffc3e4e3670057aa3c582016e /net/http/partial_data.cc
parent93d3f0b6a87b6b474439e7368aec64b30b0e9295 (diff)
downloadchromium_src-ab80bac7428906fccfafbc4d620538ded23a2a83.zip
chromium_src-ab80bac7428906fccfafbc4d620538ded23a2a83.tar.gz
chromium_src-ab80bac7428906fccfafbc4d620538ded23a2a83.tar.bz2
Revert 62171 - Http cache: make sure that we revalidate a cached entry
when the requested byte range looks wrong. We postpone the decision about what to do with a cached entry until we receive confirmation from the server, so we cannot skip asking the server about it!. This CL also makes it so that if the server returns 304 (so that our cached copy is curent), we don't destroy the entry, and we return 416 (bad range request) to the caller. BUG=58047 TEST=net_unittests Review URL: http://codereview.chromium.org/3611013 TBR=rvargas@google.com Review URL: http://codereview.chromium.org/3644005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62175 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/partial_data.cc')
-rw-r--r--net/http/partial_data.cc46
1 files changed, 12 insertions, 34 deletions
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 799c3fa..54900b3 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -127,9 +127,6 @@ bool PartialData::Init(const HttpRequestHeaders& headers) {
resource_size_ = 0;
current_range_start_ = byte_range_.first_byte_position();
-
- DVLOG(1) << "Range start: " << current_range_start_ << " end: " <<
- byte_range_.last_byte_position();
return true;
}
@@ -157,8 +154,6 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
if (!len)
return 0;
- DVLOG(3) << "ShouldValidateCache len: " << len;
-
if (sparse_entry_) {
DCHECK(!callback_);
Core* core = Core::CreateCore(this);
@@ -176,12 +171,6 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
cached_start_ = 0;
}
} else {
- if (byte_range_.HasFirstBytePosition() &&
- byte_range_.first_byte_position() >= resource_size_) {
- // The caller should take care of this condition because we should have
- // failed IsRequestedRangeOK(), but it's better to be consistent here.
- len = 0;
- }
cached_min_len_ = len;
cached_start_ = current_range_start_;
}
@@ -261,7 +250,6 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers,
DCHECK(byte_range_.IsValid());
sparse_entry_ = false;
resource_size_ = entry->GetDataSize(kDataStream);
- DVLOG(2) << "UpdateFromStoredHeaders size: " << resource_size_;
return true;
}
@@ -347,36 +335,28 @@ bool PartialData::ResponseHeadersOK(const HttpResponseHeaders* headers) {
// We are making multiple requests to complete the range requested by the user.
// Just assume that everything is fine and say that we are returning what was
// requested.
-void PartialData::FixResponseHeaders(HttpResponseHeaders* headers,
- bool success) {
+void PartialData::FixResponseHeaders(HttpResponseHeaders* headers) {
if (truncated_)
return;
headers->RemoveHeader(kLengthHeader);
headers->RemoveHeader(kRangeHeader);
- int64 range_len, start, end;
+ int64 range_len;
if (byte_range_.IsValid()) {
- if (success) {
- if (!sparse_entry_)
- headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content");
-
- DCHECK(byte_range_.HasFirstBytePosition());
- DCHECK(byte_range_.HasLastBytePosition());
- start = byte_range_.first_byte_position();
- end = byte_range_.last_byte_position();
- range_len = end - start + 1;
- } else {
- headers->ReplaceStatusLine(
- "HTTP/1.1 416 Requested Range Not Satisfiable");
- start = 0;
- end = 0;
- range_len = 0;
- }
+ if (!sparse_entry_)
+ headers->ReplaceStatusLine("HTTP/1.1 206 Partial Content");
+ DCHECK(byte_range_.HasFirstBytePosition());
+ DCHECK(byte_range_.HasLastBytePosition());
headers->AddHeader(
base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64,
- kRangeHeader, start, end, resource_size_));
+ kRangeHeader,
+ byte_range_.first_byte_position(),
+ byte_range_.last_byte_position(),
+ resource_size_));
+ range_len = byte_range_.last_byte_position() -
+ byte_range_.first_byte_position() + 1;
} else {
// TODO(rvargas): Is it safe to change the protocol version?
headers->ReplaceStatusLine("HTTP/1.1 200 OK");
@@ -416,7 +396,6 @@ int PartialData::CacheRead(disk_cache::Entry* entry, IOBuffer* data,
int PartialData::CacheWrite(disk_cache::Entry* entry, IOBuffer* data,
int data_len, CompletionCallback* callback) {
- DVLOG(3) << "To write: " << data_len;
if (sparse_entry_) {
return entry->WriteSparseData(current_range_start_, data, data_len,
callback);
@@ -430,7 +409,6 @@ int PartialData::CacheWrite(disk_cache::Entry* entry, IOBuffer* data,
}
void PartialData::OnCacheReadCompleted(int result) {
- DVLOG(3) << "Read: " << result;
if (result > 0) {
current_range_start_ += result;
cached_min_len_ -= result;