Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1182)

Unified Diff: net/http/http_cache.cc

Issue 52028: Net module changes to support caching responses to a POST request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache.cc
===================================================================
--- net/http/http_cache.cc (revision 12361)
+++ net/http/http_cache.cc (working copy)
@@ -118,38 +118,6 @@
//-----------------------------------------------------------------------------
-std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
- std::string url = request->url.spec();
- if (request->url.has_ref())
- url.erase(url.find_last_of('#'));
-
- if (mode_ == NORMAL) {
- return url;
- }
-
- // In playback and record mode, we cache everything.
-
- // Lazily initialize.
- if (playback_cache_map_ == NULL)
- playback_cache_map_.reset(new PlaybackCacheMap());
-
- // Each time we request an item from the cache, we tag it with a
- // generation number. During playback, multiple fetches for the same
- // item will use the same generation number and pull the proper
- // instance of an URL from the cache.
- int generation = 0;
- DCHECK(playback_cache_map_ != NULL);
- if (playback_cache_map_->find(url) != playback_cache_map_->end())
- generation = (*playback_cache_map_)[url];
- (*playback_cache_map_)[url] = generation + 1;
-
- // The key into the cache is GENERATION # + METHOD + URL.
- std::string result = IntToString(generation);
- result.append(request->method);
- result.append(url);
- return result;
-}
-
//-----------------------------------------------------------------------------
HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* e)
@@ -667,11 +635,15 @@
if (effective_load_flags_ & LOAD_DISABLE_CACHE)
return true;
- // TODO(darin): add support for caching HEAD and POST responses
- if (request_->method != "GET")
- return true;
+ if (request_->method == "GET")
+ return false;
- return false;
+ if (request_->method == "POST" &&
+ request_->upload_data && request_->upload_data->identifier())
+ return false;
+
+ // TODO(darin): add support for caching HEAD responses
+ return true;
}
int HttpCache::Transaction::BeginCacheRead() {
@@ -1207,6 +1179,43 @@
true) == len;
}
+// Generate a key that can be used inside the cache.
+std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
+ std::string url = request->url.spec();
+ if (request->url.has_ref())
+ url.erase(url.find_last_of('#'));
+
+ if (mode_ == NORMAL) {
+ // No valid URL can begin with numerals, so we should not have to worry
+ // about collisions with normal URLs.
+ if (request->upload_data && request->upload_data->identifier())
+ url.insert(0, StringPrintf("%lld/", request->upload_data->identifier()));
+ return url;
+ }
+
+ // In playback and record mode, we cache everything.
+
+ // Lazily initialize.
+ if (playback_cache_map_ == NULL)
+ playback_cache_map_.reset(new PlaybackCacheMap());
+
+ // Each time we request an item from the cache, we tag it with a
+ // generation number. During playback, multiple fetches for the same
+ // item will use the same generation number and pull the proper
+ // instance of an URL from the cache.
+ int generation = 0;
+ DCHECK(playback_cache_map_ != NULL);
+ if (playback_cache_map_->find(url) != playback_cache_map_->end())
+ generation = (*playback_cache_map_)[url];
+ (*playback_cache_map_)[url] = generation + 1;
+
+ // The key into the cache is GENERATION # + METHOD + URL.
+ std::string result = IntToString(generation);
+ result.append(request->method);
+ result.append(url);
+ return result;
+}
+
void HttpCache::DoomEntry(const std::string& key) {
// Need to abandon the ActiveEntry, but any transaction attached to the entry
// should not be impacted. Dooming an entry only means that it will no
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698