diff options
author | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 18:22:23 +0000 |
---|---|---|
committer | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 18:22:23 +0000 |
commit | bdd42287e26666cb9230de0102045ccaa1e29207 (patch) | |
tree | fa5b66de3a049c67045e3cb5014b9d4d172efe17 /webkit/appcache/appcache_update_job.cc | |
parent | 1c5491c13d721e264432fe75e4030017b1ee10e8 (diff) | |
download | chromium_src-bdd42287e26666cb9230de0102045ccaa1e29207.zip chromium_src-bdd42287e26666cb9230de0102045ccaa1e29207.tar.gz chromium_src-bdd42287e26666cb9230de0102045ccaa1e29207.tar.bz2 |
Make appcache update conditionally include If-Modified-Since and If-None-Match headers when fetching a manifest.
TEST=new tests added
BUG=none
Review URL: http://codereview.chromium.org/500152
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_update_job.cc')
-rw-r--r-- | webkit/appcache/appcache_update_job.cc | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index de7b73c..dbd763f8 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -198,10 +198,58 @@ void AppCacheUpdateJob::FetchManifest(bool is_first_fetch) { UpdateJobInfo::MANIFEST_FETCH : UpdateJobInfo::MANIFEST_REFETCH; manifest_url_request_->SetUserData(this, new UpdateJobInfo(fetch_type)); manifest_url_request_->set_context(service_->request_context()); - // TODO(jennb): add "If-Modified-Since" if have previous date manifest_url_request_->set_load_flags( manifest_url_request_->load_flags() | net::LOAD_DISABLE_INTERCEPT); - manifest_url_request_->Start(); + + // Add any necessary Http headers before sending fetch request. + if (is_first_fetch) { + AppCacheEntry* entry = (update_type_ == UPGRADE_ATTEMPT) ? + group_->newest_complete_cache()->GetEntry(manifest_url_) : NULL; + if (entry) { + // Asynchronously load response info for manifest from newest cache. + service_->storage()->LoadResponseInfo(manifest_url_, + entry->response_id(), this); + } else { + AddHttpHeadersAndFetch(manifest_url_request_, NULL); + } + } else { + DCHECK(internal_state_ == REFETCH_MANIFEST); + DCHECK(manifest_response_info_.get()); + AddHttpHeadersAndFetch(manifest_url_request_, + manifest_response_info_.get()); + } +} + +void AppCacheUpdateJob::AddHttpHeadersAndFetch( + URLRequest* request, const net::HttpResponseInfo* info) { + DCHECK(request); + if (info) { + std::string extra_headers; + + // Add If-Modified-Since header if response info has Last-Modified header. + const std::string last_modified = "Last-Modified"; + std::string last_modified_value; + info->headers->EnumerateHeader(NULL, last_modified, &last_modified_value); + if (!last_modified_value.empty()) { + extra_headers.append("If-Modified-Since: "); + extra_headers.append(last_modified_value); + } + + // Add If-None-Match header if resposne info has ETag header. + const std::string etag = "ETag"; + std::string etag_value; + info->headers->EnumerateHeader(NULL, etag, &etag_value); + if (!etag_value.empty()) { + if (!extra_headers.empty()) + extra_headers.append("\r\n"); + extra_headers.append("If-None-Match: "); + extra_headers.append(etag_value); + } + + if (!extra_headers.empty()) + request->SetExtraRequestHeaders(extra_headers); + } + request->Start(); } void AppCacheUpdateJob::OnResponseStarted(URLRequest *request) { @@ -1018,17 +1066,24 @@ bool AppCacheUpdateJob::MaybeLoadFromNewestCache(const GURL& url, void AppCacheUpdateJob::OnResponseInfoLoaded( AppCacheResponseInfo* response_info, int64 response_id) { + const net::HttpResponseInfo* http_info = response_info ? + response_info->http_response_info() : NULL; + + // Needed response info for a manifest fetch request. + if (internal_state_ == FETCH_MANIFEST) { + AddHttpHeadersAndFetch(manifest_url_request_, http_info); + return; + } + LoadingResponses::iterator found = loading_responses_.find(response_id); DCHECK(found != loading_responses_.end()); const GURL& url = found->second; - if (!response_info) { + if (!http_info) { LoadFromNewestCacheFailed(url); // no response found } else { // Check if response can be re-used according to HTTP caching semantics. // Responses with a "vary" header get treated as expired. - const net::HttpResponseInfo* http_info = - response_info->http_response_info(); const std::string name = "vary"; std::string value; void* iter = NULL; |