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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/http/http_cache_unittest.cc » ('j') | net/http/http_cache_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 // From http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-21#section-6 166 // From http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-21#section-6
167 // a "non-error response" is one with a 2xx (Successful) or 3xx 167 // a "non-error response" is one with a 2xx (Successful) or 3xx
168 // (Redirection) status code. 168 // (Redirection) status code.
169 bool NonErrorResponse(int status_code) { 169 bool NonErrorResponse(int status_code) {
170 int status_code_range = status_code / 100; 170 int status_code_range = status_code / 100;
171 return status_code_range == 2 || status_code_range == 3; 171 return status_code_range == 2 || status_code_range == 3;
172 } 172 }
173 173
174 // 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.
175 // the safety is not known.
176 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.
177 if (method == "GET" || method == "HEAD" || method == "OPTIONS" ||
178 method == "TRACE") {
179 return true;
180 }
181 return false;
182 }
183
174 // Error codes that will be considered indicative of a page being offline/ 184 // Error codes that will be considered indicative of a page being offline/
175 // unreachable for LOAD_FROM_CACHE_IF_OFFLINE. 185 // unreachable for LOAD_FROM_CACHE_IF_OFFLINE.
176 bool IsOfflineError(int error) { 186 bool IsOfflineError(int error) {
177 return (error == net::ERR_NAME_NOT_RESOLVED || 187 return (error == net::ERR_NAME_NOT_RESOLVED ||
178 error == net::ERR_INTERNET_DISCONNECTED || 188 error == net::ERR_INTERNET_DISCONNECTED ||
179 error == net::ERR_ADDRESS_UNREACHABLE || 189 error == net::ERR_ADDRESS_UNREACHABLE ||
180 error == net::ERR_CONNECTION_TIMED_OUT); 190 error == net::ERR_CONNECTION_TIMED_OUT);
181 } 191 }
182 192
183 // Enum for UMA, indicating the status (with regard to offline mode) of 193 // Enum for UMA, indicating the status (with regard to offline mode) of
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 (request_->method == "PUT" || request_->method == "DELETE")) { 1241 (request_->method == "PUT" || request_->method == "DELETE")) {
1232 if (NonErrorResponse(new_response->headers->response_code())) { 1242 if (NonErrorResponse(new_response->headers->response_code())) {
1233 int ret = cache_->DoomEntry(cache_key_, NULL); 1243 int ret = cache_->DoomEntry(cache_key_, NULL);
1234 DCHECK_EQ(OK, ret); 1244 DCHECK_EQ(OK, ret);
1235 } 1245 }
1236 cache_->DoneWritingToEntry(entry_, true); 1246 cache_->DoneWritingToEntry(entry_, true);
1237 entry_ = NULL; 1247 entry_ = NULL;
1238 mode_ = NONE; 1248 mode_ = NONE;
1239 } 1249 }
1240 1250
1251 // If this is a successful request having a unsafe method, invalidate
1252 // the URL given in the Content-Location header if it has the same origin as
1253 // |request_->url|.
1254 if (!SafeHTTPMethod(request_->method) &&
1255 NonErrorResponse(new_response->headers->response_code())) {
1256 std::string content_location;
1257 if (new_response_->headers->EnumerateHeader(NULL, "Content-Location",
1258 &content_location)) {
1259 GURL absolute_location_url = request_->url.Resolve(content_location);
1260 if (absolute_location_url.is_valid() &&
1261 absolute_location_url.host() == request_->url.host()) {
1262 cache_->DoomMainEntryForUrl(absolute_location_url);
1263 }
1264 }
1265 }
1266
1241 // Invalidate any cached GET with a successful POST. 1267 // Invalidate any cached GET with a successful POST.
1242 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) && 1268 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) &&
1243 request_->method == "POST" && 1269 request_->method == "POST" &&
1244 NonErrorResponse(new_response->headers->response_code())) { 1270 NonErrorResponse(new_response->headers->response_code())) {
1245 cache_->DoomMainEntryForUrl(request_->url); 1271 cache_->DoomMainEntryForUrl(request_->url);
1246 } 1272 }
1247 1273
1248 RecordNoStoreHeaderHistogram(request_->load_flags, new_response); 1274 RecordNoStoreHeaderHistogram(request_->load_flags, new_response);
1249 1275
1250 if (new_response_->headers->response_code() == 416 && 1276 if (new_response_->headers->response_code() == 416 &&
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
3032 default: 3058 default:
3033 NOTREACHED(); 3059 NOTREACHED();
3034 } 3060 }
3035 } 3061 }
3036 3062
3037 void HttpCache::Transaction::OnIOComplete(int result) { 3063 void HttpCache::Transaction::OnIOComplete(int result) {
3038 DoLoop(result); 3064 DoLoop(result);
3039 } 3065 }
3040 3066
3041 } // namespace net 3067 } // namespace net
OLDNEW
« 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