summaryrefslogtreecommitdiffstats
path: root/net/http/http_cache_transaction.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 18:08:25 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 18:08:25 +0000
commit634739bf391585057f2f1a9f8f173d418958ae0f (patch)
treec68d3b382be4edaebf5aec10de6dba870563df7b /net/http/http_cache_transaction.cc
parent18699b72815f6f435c4e00f4f1eb900440898468 (diff)
downloadchromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.zip
chromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.tar.gz
chromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.tar.bz2
Http cache: Fix handling of truncated entries.
- Always validate a truncated entry. Furthermore, given that a server can say not-modified (304), followed by 200 when actually asked for the final range, now we validate truncated entries by asking for the next byte that we need. - If a server refuses to serve a byte range and instead sends the whole resource, we just cache the response as if nothing was stored before. - If we receive a network error while reading from the net, we don't discard the cached entry right away. Now we wait until the transaction is closed, and attempt to mark the entry as truncated. BUG=48468 TEST=net_unittests Review URL: http://codereview.chromium.org/6588105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_transaction.cc')
-rw-r--r--net/http/http_cache_transaction.cc28
1 files changed, 27 insertions, 1 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 32386f0..6665d5ff 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -731,6 +731,11 @@ int HttpCache::Transaction::DoNetworkReadComplete(int result) {
if (!cache_)
return ERR_UNEXPECTED;
+ // If there is an error and we are saving the data, just tell the user about
+ // it and wait until the destructor runs to see if we can keep the data.
+ if (mode_ != NONE && result < 0)
+ return result;
+
next_state_ = STATE_CACHE_WRITE_DATA;
return result;
}
@@ -982,6 +987,16 @@ int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) {
// We no longer need the network transaction, so destroy it.
final_upload_progress_ = network_trans_->GetUploadProgress();
network_trans_.reset();
+ } else if (entry_ && server_responded_206_ && truncated_ &&
+ partial_->initial_validation()) {
+ // We just finished the validation of a truncated entry, and the server
+ // is willing to resume the operation. Now we go back and start serving
+ // the first part to the user.
+ network_trans_.reset();
+ new_response_ = NULL;
+ next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
+ partial_->SetRangeToStartDownload();
+ return OK;
}
next_state_ = STATE_OVERWRITE_CACHED_RESPONSE;
return OK;
@@ -1442,6 +1457,9 @@ int HttpCache::Transaction::BeginCacheValidation() {
bool skip_validation = effective_load_flags_ & LOAD_PREFERRING_CACHE ||
!RequiresValidation();
+ if (truncated_)
+ skip_validation = !partial_->initial_validation();
+
if ((partial_.get() && !partial_->IsCurrentRangeCached()) || invalid_range_)
skip_validation = false;
@@ -1738,8 +1756,16 @@ bool HttpCache::Transaction::ValidatePartialResponse(bool* partial_content) {
// 304 is not expected here, but we'll spare the entry (unless it was
// truncated).
- if (truncated_)
+ if (truncated_) {
+ if (!reading_ && response_code == 200) {
+ // The server is sending the whole resource, and we can save it.
+ DCHECK(!partial_->IsLastRange());
+ partial_.reset();
+ truncated_ = false;
+ return true;
+ }
failure = true;
+ }
}
if (failure) {