OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 } | 688 } |
689 | 689 |
690 if (!location.is_valid()) | 690 if (!location.is_valid()) |
691 return ERR_INVALID_URL; | 691 return ERR_INVALID_URL; |
692 | 692 |
693 if (!job_->IsSafeRedirect(location)) { | 693 if (!job_->IsSafeRedirect(location)) { |
694 DVLOG(1) << "disallowing redirect: unsafe protocol"; | 694 DVLOG(1) << "disallowing redirect: unsafe protocol"; |
695 return ERR_UNSAFE_REDIRECT; | 695 return ERR_UNSAFE_REDIRECT; |
696 } | 696 } |
697 | 697 |
698 bool strip_post_specific_headers = false; | 698 // NOTE: Even though RFC 2616 says to preserve the request method when |
699 if (http_status_code != 307) { | 699 // following a 302 redirect, normal browsers don't do that. Instead, they |
700 // NOTE: Even though RFC 2616 says to preserve the request method when | 700 // all convert a POST into a GET in response to a 302 and so shall we. For |
701 // following a 302 redirect, normal browsers don't do that. Instead, they | 701 // 307 redirects, browsers preserve the method. The RFC says to prompt the |
702 // all convert a POST into a GET in response to a 302 and so shall we. For | 702 // user to confirm the generation of a new requests, other than GET and HEAD |
wtc
2011/10/25 18:04:48
Nit: "a new requests" has a grammatical error. I
wtc
2011/10/25 18:33:39
mmenke: it is less important to reference httpbis.
mmenke
2011/10/25 18:54:00
How's this:
// For 303 redirects, all request m
| |
703 // 307 redirects, browsers preserve the method. The RFC says to prompt the | 703 // requests, but IE omits these prompts and so shall we. |
704 // user to confirm the generation of a new POST request, but IE omits this | 704 bool was_post = method_ == "POST"; |
705 // prompt and so shall we. | 705 if (http_status_code == 303 || |
706 strip_post_specific_headers = method_ == "POST"; | 706 ((http_status_code == 301 || http_status_code == 302) && was_post)) { |
707 method_ = "GET"; | 707 method_ = "GET"; |
708 upload_ = NULL; | 708 upload_ = NULL; |
709 if (was_post) { | |
710 // If being switched from POST to GET, must remove headers that were | |
711 // specific to the POST and don't have meaning in GET. For example | |
712 // the inclusion of a multipart Content-Type header in GET can cause | |
713 // problems with some servers: | |
714 // http://code.google.com/p/chromium/issues/detail?id=843 | |
715 StripPostSpecificHeaders(&extra_request_headers_); | |
716 } | |
709 } | 717 } |
710 | 718 |
711 // Suppress the referrer if we're redirecting out of https. | 719 // Suppress the referrer if we're redirecting out of https. |
712 if (GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) | 720 if (GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) |
713 referrer_.clear(); | 721 referrer_.clear(); |
714 | 722 |
715 url_chain_.push_back(location); | 723 url_chain_.push_back(location); |
716 --redirect_limit_; | 724 --redirect_limit_; |
717 | 725 |
718 if (strip_post_specific_headers) { | |
719 // If being switched from POST to GET, must remove headers that were | |
720 // specific to the POST and don't have meaning in GET. For example | |
721 // the inclusion of a multipart Content-Type header in GET can cause | |
722 // problems with some servers: | |
723 // http://code.google.com/p/chromium/issues/detail?id=843 | |
724 StripPostSpecificHeaders(&extra_request_headers_); | |
725 } | |
726 | |
727 if (!final_upload_progress_) | 726 if (!final_upload_progress_) |
728 final_upload_progress_ = job_->GetUploadProgress(); | 727 final_upload_progress_ = job_->GetUploadProgress(); |
729 | 728 |
730 PrepareToRestart(); | 729 PrepareToRestart(); |
731 Start(); | 730 Start(); |
732 return OK; | 731 return OK; |
733 } | 732 } |
734 | 733 |
735 const URLRequestContext* URLRequest::context() const { | 734 const URLRequestContext* URLRequest::context() const { |
736 return context_.get(); | 735 return context_.get(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 | 887 |
889 void URLRequest::SetUnblockedOnDelegate() { | 888 void URLRequest::SetUnblockedOnDelegate() { |
890 if (!blocked_on_delegate_) | 889 if (!blocked_on_delegate_) |
891 return; | 890 return; |
892 blocked_on_delegate_ = false; | 891 blocked_on_delegate_ = false; |
893 load_state_param_.clear(); | 892 load_state_param_.clear(); |
894 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 893 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
895 } | 894 } |
896 | 895 |
897 } // namespace net | 896 } // namespace net |
OLD | NEW |