| 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.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 910 |
| 911 load_timing_info_ = LoadTimingInfo(); | 911 load_timing_info_ = LoadTimingInfo(); |
| 912 load_timing_info_.request_start_time = response_info_.request_time; | 912 load_timing_info_.request_start_time = response_info_.request_time; |
| 913 load_timing_info_.request_start = base::TimeTicks::Now(); | 913 load_timing_info_.request_start = base::TimeTicks::Now(); |
| 914 | 914 |
| 915 status_ = URLRequestStatus(); | 915 status_ = URLRequestStatus(); |
| 916 is_pending_ = false; | 916 is_pending_ = false; |
| 917 proxy_server_ = ProxyServer(); | 917 proxy_server_ = ProxyServer(); |
| 918 } | 918 } |
| 919 | 919 |
| 920 int URLRequest::Redirect(const RedirectInfo& redirect_info) { | 920 void URLRequest::Redirect(const RedirectInfo& redirect_info) { |
| 921 // Matches call in NotifyReceivedRedirect. | 921 // This method always succeeds. Whether |job_| is allowed to redirect to |
| 922 // |redirect_info| is checked in URLRequestJob::CanFollowRedirect, before |
| 923 // NotifyReceivedRedirect. This means the delegate can assume that, if it |
| 924 // accepted the redirect, future calls to OnResponseStarted correspond to |
| 925 // |redirect_info.new_url|. |
| 922 OnCallToDelegateComplete(); | 926 OnCallToDelegateComplete(); |
| 923 if (net_log_.IsCapturing()) { | 927 if (net_log_.IsCapturing()) { |
| 924 net_log_.AddEvent( | 928 net_log_.AddEvent( |
| 925 NetLogEventType::URL_REQUEST_REDIRECTED, | 929 NetLogEventType::URL_REQUEST_REDIRECTED, |
| 926 NetLog::StringCallback("location", | 930 NetLog::StringCallback("location", |
| 927 &redirect_info.new_url.possibly_invalid_spec())); | 931 &redirect_info.new_url.possibly_invalid_spec())); |
| 928 } | 932 } |
| 929 | 933 |
| 930 if (network_delegate_) | 934 if (network_delegate_) |
| 931 network_delegate_->NotifyBeforeRedirect(this, redirect_info.new_url); | 935 network_delegate_->NotifyBeforeRedirect(this, redirect_info.new_url); |
| 932 | 936 |
| 933 if (redirect_limit_ <= 0) { | |
| 934 DVLOG(1) << "disallowing redirect: exceeds limit"; | |
| 935 return ERR_TOO_MANY_REDIRECTS; | |
| 936 } | |
| 937 | |
| 938 if (!redirect_info.new_url.is_valid()) | |
| 939 return ERR_INVALID_URL; | |
| 940 | |
| 941 if (!job_->IsSafeRedirect(redirect_info.new_url)) { | |
| 942 DVLOG(1) << "disallowing redirect: unsafe protocol"; | |
| 943 return ERR_UNSAFE_REDIRECT; | |
| 944 } | |
| 945 | |
| 946 if (!final_upload_progress_.position() && upload_data_stream_) | 937 if (!final_upload_progress_.position() && upload_data_stream_) |
| 947 final_upload_progress_ = upload_data_stream_->GetUploadProgress(); | 938 final_upload_progress_ = upload_data_stream_->GetUploadProgress(); |
| 948 PrepareToRestart(); | 939 PrepareToRestart(); |
| 949 | 940 |
| 950 if (redirect_info.new_method != method_) { | 941 if (redirect_info.new_method != method_) { |
| 951 // TODO(davidben): This logic still needs to be replicated at the consumers. | 942 // TODO(davidben): This logic still needs to be replicated at the consumers. |
| 952 if (method_ == "POST") { | 943 if (method_ == "POST") { |
| 953 // If being switched from POST, must remove Origin header. | 944 // If being switched from POST, must remove Origin header. |
| 954 // TODO(jww): This is Origin header removal is probably layering violation | 945 // TODO(jww): This is Origin header removal is probably layering violation |
| 955 // and | 946 // and |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 981 |
| 991 referrer_ = redirect_info.new_referrer; | 982 referrer_ = redirect_info.new_referrer; |
| 992 referrer_policy_ = redirect_info.new_referrer_policy; | 983 referrer_policy_ = redirect_info.new_referrer_policy; |
| 993 first_party_for_cookies_ = redirect_info.new_first_party_for_cookies; | 984 first_party_for_cookies_ = redirect_info.new_first_party_for_cookies; |
| 994 token_binding_referrer_ = redirect_info.referred_token_binding_host; | 985 token_binding_referrer_ = redirect_info.referred_token_binding_host; |
| 995 | 986 |
| 996 url_chain_.push_back(redirect_info.new_url); | 987 url_chain_.push_back(redirect_info.new_url); |
| 997 --redirect_limit_; | 988 --redirect_limit_; |
| 998 | 989 |
| 999 Start(); | 990 Start(); |
| 1000 return OK; | |
| 1001 } | 991 } |
| 1002 | 992 |
| 1003 const URLRequestContext* URLRequest::context() const { | 993 const URLRequestContext* URLRequest::context() const { |
| 1004 return context_; | 994 return context_; |
| 1005 } | 995 } |
| 1006 | 996 |
| 1007 int64_t URLRequest::GetExpectedContentSize() const { | 997 int64_t URLRequest::GetExpectedContentSize() const { |
| 1008 int64_t expected_content_size = -1; | 998 int64_t expected_content_size = -1; |
| 1009 if (job_.get()) | 999 if (job_.get()) |
| 1010 expected_content_size = job_->expected_content_size(); | 1000 expected_content_size = job_->expected_content_size(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 out->clear(); | 1206 out->clear(); |
| 1217 } | 1207 } |
| 1218 | 1208 |
| 1219 void URLRequest::set_status(URLRequestStatus status) { | 1209 void URLRequest::set_status(URLRequestStatus status) { |
| 1220 DCHECK(status_.is_io_pending() || status_.is_success() || | 1210 DCHECK(status_.is_io_pending() || status_.is_success() || |
| 1221 (!status.is_success() && !status.is_io_pending())); | 1211 (!status.is_success() && !status.is_io_pending())); |
| 1222 status_ = status; | 1212 status_ = status; |
| 1223 } | 1213 } |
| 1224 | 1214 |
| 1225 } // namespace net | 1215 } // namespace net |
| OLD | NEW |