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

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: Don't invalidate if cache is disabled Created 5 years, 7 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') | no next file with comments »
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 90a984613adf8d5e58becb8a643e22a33465c667..c13fa37a19688b12edc52bca6200c92aec00dbfd 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -173,6 +173,17 @@ 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
+// the safety is not known. Safe methods are defined at
+// https://tools.ietf.org/html/rfc7231#section-4.2.1
+bool SafeHttpMethod(const std::string& method) {
+ if (method == "GET" || method == "HEAD" || method == "OPTIONS" ||
+ method == "TRACE") {
+ return true;
+ }
+ return false;
+}
+
void RecordNoStoreHeaderHistogram(int load_flags,
const HttpResponseInfo* response) {
if (load_flags & LOAD_MAIN_FRAME) {
@@ -1182,6 +1193,24 @@ int HttpCache::Transaction::DoSuccessfulSendRequest() {
mode_ = NONE;
}
+ // https://tools.ietf.org/html/rfc7234#section-4.4
+ // If this is a successful request using an unsafe method, invalidate the URL
+ // given in the Content-Location header if it has the same host as
+ // |request_->url|.
+ if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) &&
+ !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);
Ryan Sleevi 2015/05/29 22:04:51 To add to Eric's concerns about scheme, this also
+ }
+ }
+ }
+
// 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698