Chromium Code Reviews| 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" && |