OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/trace_event.h" | 10 #include "base/trace_event.h" |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (establishing_tunnel_) | 820 if (establishing_tunnel_) |
821 return ERR_TUNNEL_CONNECTION_FAILED; | 821 return ERR_TUNNEL_CONNECTION_FAILED; |
822 | 822 |
823 // HTTP/0.9 doesn't support the PUT method, so lack of response headers | 823 // HTTP/0.9 doesn't support the PUT method, so lack of response headers |
824 // indicates a buggy server. See: | 824 // indicates a buggy server. See: |
825 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 | 825 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 |
826 if (request_->method == "PUT") | 826 if (request_->method == "PUT") |
827 return ERR_METHOD_NOT_SUPPORTED; | 827 return ERR_METHOD_NOT_SUPPORTED; |
828 } | 828 } |
829 | 829 |
| 830 if (establishing_tunnel_) { |
| 831 if (headers->response_code() == 200) { |
| 832 if (header_buf_body_offset_ != header_buf_len_) { |
| 833 // The proxy sent extraneous data after the headers. |
| 834 return ERR_TUNNEL_CONNECTION_FAILED; |
| 835 } |
| 836 next_state_ = STATE_SSL_CONNECT_OVER_TUNNEL; |
| 837 // Reset for the real request and response headers. |
| 838 request_headers_.clear(); |
| 839 request_headers_bytes_sent_ = 0; |
| 840 header_buf_len_ = 0; |
| 841 header_buf_body_offset_ = 0; |
| 842 establishing_tunnel_ = false; |
| 843 return OK; |
| 844 } |
| 845 // Sanitize any illegal response code for CONNECT to prevent us from |
| 846 // handling it by mistake. See http://crbug.com/7338. |
| 847 if (headers->response_code() < 400 || headers->response_code() > 599) |
| 848 headers->set_response_code(500); // Masquerade as a 500. |
| 849 } |
| 850 |
830 // Check for an intermediate 100 Continue response. An origin server is | 851 // Check for an intermediate 100 Continue response. An origin server is |
831 // allowed to send this response even if we didn't ask for it, so we just | 852 // allowed to send this response even if we didn't ask for it, so we just |
832 // need to skip over it. | 853 // need to skip over it. |
833 if (headers->response_code() == 100) { | 854 if (headers->response_code() == 100) { |
834 header_buf_len_ -= header_buf_body_offset_; | 855 header_buf_len_ -= header_buf_body_offset_; |
835 // If we've already received some bytes after the 100 Continue response, | 856 // If we've already received some bytes after the 100 Continue response, |
836 // move them to the beginning of header_buf_. | 857 // move them to the beginning of header_buf_. |
837 if (header_buf_len_) { | 858 if (header_buf_len_) { |
838 memmove(header_buf_.get(), header_buf_.get() + header_buf_body_offset_, | 859 memmove(header_buf_.get(), header_buf_.get() + header_buf_body_offset_, |
839 header_buf_len_); | 860 header_buf_len_); |
840 } | 861 } |
841 header_buf_body_offset_ = -1; | 862 header_buf_body_offset_ = -1; |
842 next_state_ = STATE_READ_HEADERS; | 863 next_state_ = STATE_READ_HEADERS; |
843 return OK; | 864 return OK; |
844 } | 865 } |
845 | 866 |
846 if (establishing_tunnel_ && headers->response_code() == 200) { | |
847 if (header_buf_body_offset_ != header_buf_len_) { | |
848 // The proxy sent extraneous data after the headers. | |
849 return ERR_TUNNEL_CONNECTION_FAILED; | |
850 } | |
851 next_state_ = STATE_SSL_CONNECT_OVER_TUNNEL; | |
852 // Reset for the real request and response headers. | |
853 request_headers_.clear(); | |
854 request_headers_bytes_sent_ = 0; | |
855 header_buf_len_ = 0; | |
856 header_buf_body_offset_ = 0; | |
857 establishing_tunnel_ = false; | |
858 return OK; | |
859 } | |
860 | |
861 response_.headers = headers; | 867 response_.headers = headers; |
862 response_.vary_data.Init(*request_, *response_.headers); | 868 response_.vary_data.Init(*request_, *response_.headers); |
863 | 869 |
864 int rv = HandleAuthChallenge(); | 870 int rv = HandleAuthChallenge(); |
865 if (rv == WILL_RESTART_TRANSACTION) { | 871 if (rv == WILL_RESTART_TRANSACTION) { |
866 DCHECK(next_state_ == STATE_INIT_CONNECTION); | 872 DCHECK(next_state_ == STATE_INIT_CONNECTION); |
867 return OK; | 873 return OK; |
868 } | 874 } |
869 if (rv != OK) | 875 if (rv != OK) |
870 return rv; | 876 return rv; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 | 1215 |
1210 int status = response_.headers->response_code(); | 1216 int status = response_.headers->response_code(); |
1211 if (status != 401 && status != 407) | 1217 if (status != 401 && status != 407) |
1212 return OK; | 1218 return OK; |
1213 HttpAuth::Target target = status == 407 ? | 1219 HttpAuth::Target target = status == 407 ? |
1214 HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; | 1220 HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; |
1215 | 1221 |
1216 if (target == HttpAuth::AUTH_PROXY && proxy_info_.is_direct()) | 1222 if (target == HttpAuth::AUTH_PROXY && proxy_info_.is_direct()) |
1217 return ERR_UNEXPECTED_PROXY_AUTH; | 1223 return ERR_UNEXPECTED_PROXY_AUTH; |
1218 | 1224 |
| 1225 if (target == HttpAuth::AUTH_SERVER && establishing_tunnel_) |
| 1226 return ERR_UNEXPECTED_SERVER_AUTH; |
| 1227 |
1219 // The auth we tried just failed, hence it can't be valid. Remove it from | 1228 // The auth we tried just failed, hence it can't be valid. Remove it from |
1220 // the cache so it won't be used again. | 1229 // the cache so it won't be used again. |
1221 if (HaveAuth(target)) | 1230 if (HaveAuth(target)) |
1222 InvalidateRejectedAuthFromCache(target); | 1231 InvalidateRejectedAuthFromCache(target); |
1223 | 1232 |
1224 auth_identity_[target].invalid = true; | 1233 auth_identity_[target].invalid = true; |
1225 | 1234 |
1226 // Find the best authentication challenge that we support. | 1235 // Find the best authentication challenge that we support. |
1227 HttpAuth::ChooseBestChallenge(response_.headers.get(), | 1236 HttpAuth::ChooseBestChallenge(response_.headers.get(), |
1228 target, | 1237 target, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 if (target == HttpAuth::AUTH_PROXY) { | 1271 if (target == HttpAuth::AUTH_PROXY) { |
1263 auth_info->host = ASCIIToWide(proxy_info_.proxy_server()); | 1272 auth_info->host = ASCIIToWide(proxy_info_.proxy_server()); |
1264 } else { | 1273 } else { |
1265 DCHECK(target == HttpAuth::AUTH_SERVER); | 1274 DCHECK(target == HttpAuth::AUTH_SERVER); |
1266 auth_info->host = ASCIIToWide(request_->url.host()); | 1275 auth_info->host = ASCIIToWide(request_->url.host()); |
1267 } | 1276 } |
1268 response_.auth_challenge = auth_info; | 1277 response_.auth_challenge = auth_info; |
1269 } | 1278 } |
1270 | 1279 |
1271 } // namespace net | 1280 } // namespace net |
OLD | NEW |