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 // For 303 redirects, all request methods are converted to GETs, as per RFC | 698 // For 303 redirects, all request methods except HEAD are converted to GET, |
699 // 2616. The latest httpbis draft also allows POST requests to be converted | 699 // as per the latest httpbis draft. The draft also allows POST requests to |
700 // to GETs when following 301/302 redirects for historical reasons. Most | 700 // be converted to GETs when following 301/302 redirects, for historical |
701 // major browsers do this and so shall we. The RFC says to prompt the user | 701 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and |
702 // to confirm the generation of new requests, other than GET and HEAD | 702 // the httpbis draft say to prompt the user to confirm the generation of new |
703 // requests, but IE omits these prompts and so shall we. | 703 // requests, other than GET and HEAD requests, but IE omits these prompts and |
704 // See: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-late
st.html#status.3xx | 704 // so shall we. |
| 705 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio
n-7.3 |
705 bool was_post = method_ == "POST"; | 706 bool was_post = method_ == "POST"; |
706 if (http_status_code == 303 || | 707 if ((http_status_code == 303 && method_ != "HEAD") || |
707 ((http_status_code == 301 || http_status_code == 302) && was_post)) { | 708 ((http_status_code == 301 || http_status_code == 302) && was_post)) { |
708 method_ = "GET"; | 709 method_ = "GET"; |
709 upload_ = NULL; | 710 upload_ = NULL; |
710 if (was_post) { | 711 if (was_post) { |
711 // If being switched from POST to GET, must remove headers that were | 712 // If being switched from POST to GET, must remove headers that were |
712 // specific to the POST and don't have meaning in GET. For example | 713 // specific to the POST and don't have meaning in GET. For example |
713 // the inclusion of a multipart Content-Type header in GET can cause | 714 // the inclusion of a multipart Content-Type header in GET can cause |
714 // problems with some servers: | 715 // problems with some servers: |
715 // http://code.google.com/p/chromium/issues/detail?id=843 | 716 // http://code.google.com/p/chromium/issues/detail?id=843 |
716 StripPostSpecificHeaders(&extra_request_headers_); | 717 StripPostSpecificHeaders(&extra_request_headers_); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 889 |
889 void URLRequest::SetUnblockedOnDelegate() { | 890 void URLRequest::SetUnblockedOnDelegate() { |
890 if (!blocked_on_delegate_) | 891 if (!blocked_on_delegate_) |
891 return; | 892 return; |
892 blocked_on_delegate_ = false; | 893 blocked_on_delegate_ = false; |
893 load_state_param_.clear(); | 894 load_state_param_.clear(); |
894 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 895 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
895 } | 896 } |
896 | 897 |
897 } // namespace net | 898 } // namespace net |
OLD | NEW |