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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 212543005: Do not copy reference fragments for overridden redirects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
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/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 // Even if encoding types are empty, there is a chance that we need to add 1027 // Even if encoding types are empty, there is a chance that we need to add
1028 // some decoding, as some proxies strip encoding completely. In such cases, 1028 // some decoding, as some proxies strip encoding completely. In such cases,
1029 // we may need to add (for example) SDCH filtering (when the context suggests 1029 // we may need to add (for example) SDCH filtering (when the context suggests
1030 // it is appropriate). 1030 // it is appropriate).
1031 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); 1031 Filter::FixupEncodingTypes(*filter_context_, &encoding_types);
1032 1032
1033 return !encoding_types.empty() 1033 return !encoding_types.empty()
1034 ? Filter::Factory(encoding_types, *filter_context_) : NULL; 1034 ? Filter::Factory(encoding_types, *filter_context_) : NULL;
1035 } 1035 }
1036 1036
1037 bool URLRequestHttpJob::IsRedirectResponse(GURL* location,
1038 int* http_status_code) {
1039 if (!URLRequestJob::IsRedirectResponse(location, http_status_code))
1040 return false;
1041 const GURL& url = request_->url();
1042
1043 // Move the reference fragment of the old location to the new one if the
1044 // new one has none. This duplicates mozilla's behavior.
1045 // If |allowed_unsafe_redirect_url_| is set, then we assume that the redirect
1046 // URL has been overridden by the network delegate, so the redirection URL
1047 // must not be modified.
1048 if (url.is_valid() && url.has_ref() && !location->has_ref() &&
1049 !allowed_unsafe_redirect_url_.is_valid()) {
mmenke 2014/03/27 14:41:46 This partially breaks the reason for having allowe
1050 GURL::Replacements replacements;
1051 // Reference the |ref| directly out of the original URL to avoid a malloc.
1052 replacements.SetRef(url.spec().data(),
1053 url.parsed_for_possibly_invalid_spec().ref);
1054 *location = location->ReplaceComponents(replacements);
1055 }
1056 return true;
1057 }
1058
1037 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { 1059 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) {
1038 // HTTP is always safe. 1060 // HTTP is always safe.
1039 // TODO(pauljensen): Remove once crbug.com/146591 is fixed. 1061 // TODO(pauljensen): Remove once crbug.com/146591 is fixed.
1040 if (location.is_valid() && 1062 if (location.is_valid() &&
1041 (location.scheme() == "http" || location.scheme() == "https")) { 1063 (location.scheme() == "http" || location.scheme() == "https")) {
1042 return true; 1064 return true;
1043 } 1065 }
1044 // Delegates may mark an URL as safe for redirection. 1066 // Delegates may mark a URL as safe for redirection.
1045 if (allowed_unsafe_redirect_url_.is_valid()) { 1067 if (allowed_unsafe_redirect_url_.is_valid()) {
1046 GURL::Replacements replacements; 1068 return allowed_unsafe_redirect_url_ == location;
1047 replacements.ClearRef();
1048 if (allowed_unsafe_redirect_url_.ReplaceComponents(replacements) ==
1049 location.ReplaceComponents(replacements)) {
1050 return true;
1051 }
1052 } 1069 }
1053 // Query URLRequestJobFactory as to whether |location| would be safe to 1070 // Query URLRequestJobFactory as to whether |location| would be safe to
1054 // redirect to. 1071 // redirect to.
1055 return request_->context()->job_factory() && 1072 return request_->context()->job_factory() &&
1056 request_->context()->job_factory()->IsSafeRedirectTarget(location); 1073 request_->context()->job_factory()->IsSafeRedirectTarget(location);
1057 } 1074 }
1058 1075
1059 bool URLRequestHttpJob::NeedsAuth() { 1076 bool URLRequestHttpJob::NeedsAuth() {
1060 int code = GetResponseCode(); 1077 int code = GetResponseCode();
1061 if (code == -1) 1078 if (code == -1)
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 return override_response_headers_.get() ? 1515 return override_response_headers_.get() ?
1499 override_response_headers_.get() : 1516 override_response_headers_.get() :
1500 transaction_->GetResponseInfo()->headers.get(); 1517 transaction_->GetResponseInfo()->headers.get();
1501 } 1518 }
1502 1519
1503 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1520 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1504 awaiting_callback_ = false; 1521 awaiting_callback_ = false;
1505 } 1522 }
1506 1523
1507 } // namespace net 1524 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698