Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 return; | 282 return; |
| 283 | 283 |
| 284 weak_factory_.InvalidateWeakPtrs(); | 284 weak_factory_.InvalidateWeakPtrs(); |
| 285 DestroyTransaction(); | 285 DestroyTransaction(); |
| 286 URLRequestJob::Kill(); | 286 URLRequestJob::Kill(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void URLRequestHttpJob::NotifyHeadersComplete() { | 289 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 290 DCHECK(!response_info_); | 290 DCHECK(!response_info_); |
| 291 | 291 |
| 292 if (override_redirect_url_.is_valid()) { | |
| 293 // Ignore the remainder of the response and let NotifyHeadersComplete handle | |
| 294 // the redirect. | |
| 295 URLRequestJob::NotifyHeadersComplete(); | |
| 296 return; | |
| 297 } | |
| 292 response_info_ = transaction_->GetResponseInfo(); | 298 response_info_ = transaction_->GetResponseInfo(); |
| 293 | 299 |
| 294 // Save boolean, as we'll need this info at destruction time, and filters may | 300 // Save boolean, as we'll need this info at destruction time, and filters may |
| 295 // also need this info. | 301 // also need this info. |
| 296 is_cached_content_ = response_info_->was_cached; | 302 is_cached_content_ = response_info_->was_cached; |
| 297 | 303 |
| 298 if (!is_cached_content_ && throttling_entry_.get()) { | 304 if (!is_cached_content_ && throttling_entry_.get()) { |
| 299 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders()); | 305 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders()); |
| 300 throttling_entry_->UpdateWithResponse(request_info_.url.host(), | 306 throttling_entry_->UpdateWithResponse(request_info_.url.host(), |
| 301 &response_adapter); | 307 &response_adapter); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 } | 804 } |
| 799 } | 805 } |
| 800 | 806 |
| 801 if (result == OK) { | 807 if (result == OK) { |
| 802 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); | 808 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
| 803 if (network_delegate()) { | 809 if (network_delegate()) { |
| 804 // Note that |this| may not be deleted until | 810 // Note that |this| may not be deleted until |
| 805 // |on_headers_received_callback_| or | 811 // |on_headers_received_callback_| or |
| 806 // |NetworkDelegate::URLRequestDestroyed()| has been called. | 812 // |NetworkDelegate::URLRequestDestroyed()| has been called. |
| 807 OnCallToDelegate(); | 813 OnCallToDelegate(); |
| 814 override_redirect_url_ = GURL(); | |
| 808 int error = network_delegate()->NotifyHeadersReceived( | 815 int error = network_delegate()->NotifyHeadersReceived( |
| 809 request_, | 816 request_, |
| 810 on_headers_received_callback_, | 817 on_headers_received_callback_, |
| 818 &override_redirect_url_, | |
| 811 headers.get(), | 819 headers.get(), |
| 812 &override_response_headers_); | 820 &override_response_headers_); |
| 813 if (error != net::OK) { | 821 if (error != net::OK) { |
| 814 if (error == net::ERR_IO_PENDING) { | 822 if (error == net::ERR_IO_PENDING) { |
| 815 awaiting_callback_ = true; | 823 awaiting_callback_ = true; |
| 816 } else { | 824 } else { |
| 817 std::string source("delegate"); | 825 std::string source("delegate"); |
| 818 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, | 826 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
| 819 NetLog::StringCallback("source", | 827 NetLog::StringCallback("source", |
| 820 &source)); | 828 &source)); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 // Even if encoding types are empty, there is a chance that we need to add | 1031 // Even if encoding types are empty, there is a chance that we need to add |
| 1024 // some decoding, as some proxies strip encoding completely. In such cases, | 1032 // some decoding, as some proxies strip encoding completely. In such cases, |
| 1025 // we may need to add (for example) SDCH filtering (when the context suggests | 1033 // we may need to add (for example) SDCH filtering (when the context suggests |
| 1026 // it is appropriate). | 1034 // it is appropriate). |
| 1027 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); | 1035 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); |
| 1028 | 1036 |
| 1029 return !encoding_types.empty() | 1037 return !encoding_types.empty() |
| 1030 ? Filter::Factory(encoding_types, *filter_context_) : NULL; | 1038 ? Filter::Factory(encoding_types, *filter_context_) : NULL; |
| 1031 } | 1039 } |
| 1032 | 1040 |
| 1041 bool URLRequestHttpJob::IsRedirectResponse(GURL* location, | |
| 1042 int* http_status_code) { | |
|
battre
2014/02/12 11:54:48
nit: indentation.
| |
| 1043 if (override_redirect_url_.is_valid()) { | |
| 1044 *location = GURL(override_redirect_url_); | |
| 1045 *http_status_code = 307; | |
| 1046 return true; | |
| 1047 } | |
| 1048 return URLRequestJob::IsRedirectResponse(location, http_status_code); | |
| 1049 } | |
| 1050 | |
| 1033 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { | 1051 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { |
| 1034 // HTTP is always safe. | 1052 // HTTP is always safe. |
| 1035 // TODO(pauljensen): Remove once crbug.com/146591 is fixed. | 1053 // TODO(pauljensen): Remove once crbug.com/146591 is fixed. |
| 1036 if (location.is_valid() && | 1054 if (location.is_valid() && |
| 1037 (location.scheme() == "http" || location.scheme() == "https")) { | 1055 (location.scheme() == "http" || location.scheme() == "https")) { |
| 1038 return true; | 1056 return true; |
| 1039 } | 1057 } |
| 1058 // A redirect override specified by the delegate is always safe. | |
| 1059 if (override_redirect_url_.is_valid()) { | |
| 1060 return true; | |
| 1061 } | |
| 1040 // Query URLRequestJobFactory as to whether |location| would be safe to | 1062 // Query URLRequestJobFactory as to whether |location| would be safe to |
| 1041 // redirect to. | 1063 // redirect to. |
| 1042 return request_->context()->job_factory() && | 1064 return request_->context()->job_factory() && |
| 1043 request_->context()->job_factory()->IsSafeRedirectTarget(location); | 1065 request_->context()->job_factory()->IsSafeRedirectTarget(location); |
| 1044 } | 1066 } |
| 1045 | 1067 |
| 1046 bool URLRequestHttpJob::NeedsAuth() { | 1068 bool URLRequestHttpJob::NeedsAuth() { |
| 1047 int code = GetResponseCode(); | 1069 int code = GetResponseCode(); |
| 1048 if (code == -1) | 1070 if (code == -1) |
| 1049 return false; | 1071 return false; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 return override_response_headers_.get() ? | 1488 return override_response_headers_.get() ? |
| 1467 override_response_headers_.get() : | 1489 override_response_headers_.get() : |
| 1468 transaction_->GetResponseInfo()->headers.get(); | 1490 transaction_->GetResponseInfo()->headers.get(); |
| 1469 } | 1491 } |
| 1470 | 1492 |
| 1471 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1493 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1472 awaiting_callback_ = false; | 1494 awaiting_callback_ = false; |
| 1473 } | 1495 } |
| 1474 | 1496 |
| 1475 } // namespace net | 1497 } // namespace net |
| OLD | NEW |