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

Unified Diff: net/http/http_cache_transaction.cc

Issue 1092113006: Invalidate urls given in the content-location header in requests using Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | net/http/http_cache_unittest.cc » ('j') | net/http/http_cache_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_transaction.cc
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index cebecda47aa14c2c20ff5671e65b20e660933274..9dde0720feef0249c513817ed2615f1b2c2254a0 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -171,6 +171,16 @@ bool NonErrorResponse(int status_code) {
return status_code_range == 2 || status_code_range == 3;
}
+// Return true if |method| is considered safe, or false if |method| is unsafe or
Adam Rice 2015/04/24 13:19:21 A reference to RFC7231 section 4.2.1 would be help
haavardm 2015/04/27 10:48:35 Done.
+// the safety is not known.
+bool SafeHTTPMethod(const std::string& method) {
Adam Rice 2015/04/24 13:19:21 Nitpick: capitalisation should be SafeHttpMethod.
haavardm 2015/04/27 10:48:35 Done.
+ if (method == "GET" || method == "HEAD" || method == "OPTIONS" ||
+ method == "TRACE") {
+ return true;
+ }
+ return false;
+}
+
// Error codes that will be considered indicative of a page being offline/
// unreachable for LOAD_FROM_CACHE_IF_OFFLINE.
bool IsOfflineError(int error) {
@@ -1238,6 +1248,22 @@ int HttpCache::Transaction::DoSuccessfulSendRequest() {
mode_ = NONE;
}
+ // If this is a successful request having a unsafe method, invalidate
+ // the URL given in the Content-Location header if it has the same origin as
+ // |request_->url|.
+ if (!SafeHTTPMethod(request_->method) &&
+ NonErrorResponse(new_response->headers->response_code())) {
+ std::string content_location;
+ if (new_response_->headers->EnumerateHeader(NULL, "Content-Location",
+ &content_location)) {
+ GURL absolute_location_url = request_->url.Resolve(content_location);
+ if (absolute_location_url.is_valid() &&
+ absolute_location_url.host() == request_->url.host()) {
+ cache_->DoomMainEntryForUrl(absolute_location_url);
+ }
+ }
+ }
+
// Invalidate any cached GET with a successful POST.
if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) &&
request_->method == "POST" &&
« no previous file with comments | « no previous file | net/http/http_cache_unittest.cc » ('j') | net/http/http_cache_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698