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_job.h" | 5 #include "net/url_request/url_request_job.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 request_->OnHeadersComplete(); | 450 request_->OnHeadersComplete(); |
| 451 | 451 |
| 452 GURL new_location; | 452 GURL new_location; |
| 453 int http_status_code; | 453 int http_status_code; |
| 454 | 454 |
| 455 if (IsRedirectResponse(&new_location, &http_status_code)) { | 455 if (IsRedirectResponse(&new_location, &http_status_code)) { |
| 456 // Redirect response bodies are not read. Notify the transaction | 456 // Redirect response bodies are not read. Notify the transaction |
| 457 // so it does not treat being stopped as an error. | 457 // so it does not treat being stopped as an error. |
| 458 DoneReadingRedirectResponse(); | 458 DoneReadingRedirectResponse(); |
| 459 | 459 |
| 460 // Invalid redirect targets are failed early before | |
| 461 // NotifyReceivedRedirect. This means the delegate can assume that, if it | |
| 462 // accepts the redirect, future calls to OnResponseStarted correspond to | |
| 463 // |redirect_info.new_url|. | |
| 464 int redirect_valid = CanFollowRedirect(new_location); | |
| 465 if (redirect_valid != OK) { | |
| 466 has_handled_response_ = true; | |
| 467 request_->NotifyResponseStarted( | |
| 468 URLRequestStatus::FromError(redirect_valid)); | |
|
mmenke
2017/06/05 19:25:15
Why not use OnDone()?
davidben
2017/06/05 19:44:17
Done.
| |
| 469 return; | |
| 470 } | |
| 471 | |
| 460 // When notifying the URLRequest::Delegate, it can destroy the request, | 472 // When notifying the URLRequest::Delegate, it can destroy the request, |
| 461 // which will destroy |this|. After calling to the URLRequest::Delegate, | 473 // which will destroy |this|. After calling to the URLRequest::Delegate, |
| 462 // pointer must be checked to see if |this| still exists, and if not, the | 474 // pointer must be checked to see if |this| still exists, and if not, the |
| 463 // code must return immediately. | 475 // code must return immediately. |
| 464 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); | 476 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); |
| 465 | 477 |
| 466 RedirectInfo redirect_info = | 478 RedirectInfo redirect_info = |
| 467 ComputeRedirectInfo(new_location, http_status_code); | 479 ComputeRedirectInfo(new_location, http_status_code); |
| 468 bool defer_redirect = false; | 480 bool defer_redirect = false; |
| 469 request_->NotifyReceivedRedirect(redirect_info, &defer_redirect); | 481 request_->NotifyReceivedRedirect(redirect_info, &defer_redirect); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 if (result != ERR_IO_PENDING) { | 725 if (result != ERR_IO_PENDING) { |
| 714 // If the read completes synchronously, either success or failure, invoke | 726 // If the read completes synchronously, either success or failure, invoke |
| 715 // GatherRawReadStats so we can account for the completed read. | 727 // GatherRawReadStats so we can account for the completed read. |
| 716 GatherRawReadStats(result); | 728 GatherRawReadStats(result); |
| 717 } else { | 729 } else { |
| 718 read_raw_callback_ = callback; | 730 read_raw_callback_ = callback; |
| 719 } | 731 } |
| 720 return result; | 732 return result; |
| 721 } | 733 } |
| 722 | 734 |
| 735 int URLRequestJob::CanFollowRedirect(const GURL& new_url) { | |
| 736 if (request_->redirect_limit_ <= 0) { | |
| 737 DVLOG(1) << "disallowing redirect: exceeds limit"; | |
| 738 return ERR_TOO_MANY_REDIRECTS; | |
| 739 } | |
| 740 | |
| 741 if (!new_url.is_valid()) | |
| 742 return ERR_INVALID_REDIRECT; | |
| 743 | |
| 744 if (!IsSafeRedirect(new_url)) { | |
|
mmenke
2017/06/05 19:25:15
Doesn't RDH/CRDHD currently allow redirects to sch
davidben
2017/06/05 19:44:17
Yup, this is exactly why the spec is split up in t
mmenke
2017/06/05 19:52:01
Ah, you're right. I had thought the reason we inf
| |
| 745 DVLOG(1) << "disallowing redirect: unsafe protocol"; | |
| 746 return ERR_UNSAFE_REDIRECT; | |
| 747 } | |
| 748 | |
| 749 return OK; | |
| 750 } | |
| 751 | |
| 723 void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { | 752 void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { |
| 724 int rv = request_->Redirect(redirect_info); | 753 request_->Redirect(redirect_info); |
| 725 if (rv != OK) | |
| 726 OnDone(URLRequestStatus(URLRequestStatus::FAILED, rv), true); | |
| 727 } | 754 } |
| 728 | 755 |
| 729 void URLRequestJob::GatherRawReadStats(int bytes_read) { | 756 void URLRequestJob::GatherRawReadStats(int bytes_read) { |
| 730 DCHECK(raw_read_buffer_ || bytes_read == 0); | 757 DCHECK(raw_read_buffer_ || bytes_read == 0); |
| 731 DCHECK_NE(ERR_IO_PENDING, bytes_read); | 758 DCHECK_NE(ERR_IO_PENDING, bytes_read); |
| 732 | 759 |
| 733 if (bytes_read > 0) { | 760 if (bytes_read > 0) { |
| 734 // If there is a filter, bytes will be logged after the filter is applied. | 761 // If there is a filter, bytes will be logged after the filter is applied. |
| 735 if (source_stream_->type() != SourceStream::TYPE_NONE && | 762 if (source_stream_->type() != SourceStream::TYPE_NONE && |
| 736 request()->net_log().IsCapturing()) { | 763 request()->net_log().IsCapturing()) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 int64_t total_sent_bytes = GetTotalSentBytes(); | 879 int64_t total_sent_bytes = GetTotalSentBytes(); |
| 853 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 880 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
| 854 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 881 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
| 855 network_delegate_->NotifyNetworkBytesSent( | 882 network_delegate_->NotifyNetworkBytesSent( |
| 856 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 883 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
| 857 } | 884 } |
| 858 last_notified_total_sent_bytes_ = total_sent_bytes; | 885 last_notified_total_sent_bytes_ = total_sent_bytes; |
| 859 } | 886 } |
| 860 | 887 |
| 861 } // namespace net | 888 } // namespace net |
| OLD | NEW |