OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/field_trial.h" | 8 #include "base/field_trial.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), | 215 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), |
216 user_callback_(NULL), | 216 user_callback_(NULL), |
217 session_(session), | 217 session_(session), |
218 request_(NULL), | 218 request_(NULL), |
219 pac_request_(NULL), | 219 pac_request_(NULL), |
220 connection_(new ClientSocketHandle), | 220 connection_(new ClientSocketHandle), |
221 reused_socket_(false), | 221 reused_socket_(false), |
222 headers_valid_(false), | 222 headers_valid_(false), |
223 logged_response_time(false), | 223 logged_response_time(false), |
224 using_ssl_(false), | 224 using_ssl_(false), |
225 proxy_mode_(kDirectConnection), | |
226 establishing_tunnel_(false), | 225 establishing_tunnel_(false), |
227 using_spdy_(false), | 226 using_spdy_(false), |
228 alternate_protocol_mode_( | 227 alternate_protocol_mode_( |
229 g_use_alternate_protocols ? kUnspecified : | 228 g_use_alternate_protocols ? kUnspecified : |
230 kDoNotUseAlternateProtocol), | 229 kDoNotUseAlternateProtocol), |
231 embedded_identity_used_(false), | 230 embedded_identity_used_(false), |
232 default_credentials_used_(false), | 231 default_credentials_used_(false), |
233 read_buf_len_(0), | 232 read_buf_len_(0), |
234 next_state_(STATE_NONE) { | 233 next_state_(STATE_NONE) { |
235 session->ssl_config_service()->GetSSLConfig(&ssl_config_); | 234 session->ssl_config_service()->GetSSLConfig(&ssl_config_); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 689 |
691 int HttpNetworkTransaction::DoInitConnection() { | 690 int HttpNetworkTransaction::DoInitConnection() { |
692 DCHECK(!connection_->is_initialized()); | 691 DCHECK(!connection_->is_initialized()); |
693 DCHECK(proxy_info_.proxy_server().is_valid()); | 692 DCHECK(proxy_info_.proxy_server().is_valid()); |
694 | 693 |
695 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 694 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
696 | 695 |
697 using_ssl_ = request_->url.SchemeIs("https"); | 696 using_ssl_ = request_->url.SchemeIs("https"); |
698 using_spdy_ = false; | 697 using_spdy_ = false; |
699 | 698 |
700 // TODO(vandebo) get rid of proxy_mode_, it's redundant | |
701 if (proxy_info_.is_direct()) | |
702 proxy_mode_ = kDirectConnection; | |
703 else if (proxy_info_.proxy_server().is_socks()) | |
704 proxy_mode_ = kSOCKSProxy; | |
705 else if (using_ssl_) | |
706 proxy_mode_ = kHTTPProxyUsingTunnel; | |
707 else | |
708 proxy_mode_ = kHTTPProxy; | |
709 | |
710 // Build the string used to uniquely identify connections of this type. | 699 // Build the string used to uniquely identify connections of this type. |
711 // Determine the host and port to connect to. | 700 // Determine the host and port to connect to. |
712 std::string connection_group; | 701 std::string connection_group; |
713 | 702 |
714 // |endpoint| indicates the final destination endpoint. | 703 // |endpoint| indicates the final destination endpoint. |
715 HostPortPair endpoint; | 704 HostPortPair endpoint; |
716 endpoint.host = request_->url.HostNoBrackets(); | 705 endpoint.host = request_->url.HostNoBrackets(); |
717 endpoint.port = request_->url.EffectiveIntPort(); | 706 endpoint.port = request_->url.EffectiveIntPort(); |
718 | 707 |
719 if (proxy_mode_ != kDirectConnection) { | 708 if (!proxy_info_.is_direct()) { |
720 ProxyServer proxy_server = proxy_info_.proxy_server(); | 709 ProxyServer proxy_server = proxy_info_.proxy_server(); |
721 connection_group = "proxy/" + proxy_server.ToURI() + "/"; | 710 connection_group = "proxy/" + proxy_server.ToURI() + "/"; |
722 peer_.host = proxy_server.HostNoBrackets(); | 711 peer_.host = proxy_server.HostNoBrackets(); |
723 peer_.port = proxy_server.port(); | 712 peer_.port = proxy_server.port(); |
724 } else { | 713 } else { |
725 peer_ = endpoint; | 714 peer_ = endpoint; |
726 if (alternate_protocol_mode_ == kUnspecified) { | 715 if (alternate_protocol_mode_ == kUnspecified) { |
727 const HttpAlternateProtocols& alternate_protocols = | 716 const HttpAlternateProtocols& alternate_protocols = |
728 session_->alternate_protocols(); | 717 session_->alternate_protocols(); |
729 if (alternate_protocols.HasAlternateProtocolFor(peer_)) { | 718 if (alternate_protocols.HasAlternateProtocolFor(peer_)) { |
(...skipping 23 matching lines...) Expand all Loading... |
753 if (session_->spdy_session_pool()->HasSession(peer_)) { | 742 if (session_->spdy_session_pool()->HasSession(peer_)) { |
754 using_spdy_ = true; | 743 using_spdy_ = true; |
755 return OK; | 744 return OK; |
756 } | 745 } |
757 | 746 |
758 // For a connection via HTTP proxy not using CONNECT, the connection | 747 // For a connection via HTTP proxy not using CONNECT, the connection |
759 // is to the proxy server only. For all other cases | 748 // is to the proxy server only. For all other cases |
760 // (direct, HTTP proxy CONNECT, SOCKS), the connection is up to the | 749 // (direct, HTTP proxy CONNECT, SOCKS), the connection is up to the |
761 // url endpoint. Hence we append the url data into the connection_group. | 750 // url endpoint. Hence we append the url data into the connection_group. |
762 // Note that the url endpoint may be different in the Alternate-Protocol case. | 751 // Note that the url endpoint may be different in the Alternate-Protocol case. |
763 if (proxy_mode_ == kDirectConnection) | 752 if (proxy_info_.is_direct()) |
764 connection_group = peer_.ToString(); | 753 connection_group = peer_.ToString(); |
765 else if (proxy_mode_ != kHTTPProxy) | 754 else if (using_ssl_ || proxy_info_.is_socks()) |
766 connection_group.append(endpoint.ToString()); | 755 connection_group.append(endpoint.ToString()); |
767 | 756 |
768 DCHECK(!connection_group.empty()); | 757 DCHECK(!connection_group.empty()); |
769 | 758 |
770 // If the user is refreshing the page, bypass the host cache. | 759 // If the user is refreshing the page, bypass the host cache. |
771 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || | 760 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || |
772 request_->load_flags & LOAD_DISABLE_CACHE; | 761 request_->load_flags & LOAD_DISABLE_CACHE; |
773 | 762 |
774 TCPSocketParams tcp_params(peer_.host, peer_.port, request_->priority, | 763 TCPSocketParams tcp_params(peer_.host, peer_.port, request_->priority, |
775 request_->referrer, disable_resolver_cache); | 764 request_->referrer, disable_resolver_cache); |
776 | 765 |
777 int rv; | 766 int rv; |
778 if (proxy_mode_ != kSOCKSProxy) { | 767 if (!proxy_info_.is_socks()) { |
779 rv = connection_->Init(connection_group, tcp_params, request_->priority, | 768 rv = connection_->Init(connection_group, tcp_params, request_->priority, |
780 &io_callback_, session_->tcp_socket_pool(), | 769 &io_callback_, session_->tcp_socket_pool(), |
781 net_log_); | 770 net_log_); |
782 } else { | 771 } else { |
783 bool socks_v5 = proxy_info_.proxy_server().scheme() == | 772 bool socks_v5 = proxy_info_.proxy_server().scheme() == |
784 ProxyServer::SCHEME_SOCKS5; | 773 ProxyServer::SCHEME_SOCKS5; |
785 SOCKSSocketParams socks_params(tcp_params, socks_v5, | 774 SOCKSSocketParams socks_params(tcp_params, socks_v5, |
786 request_->url.HostNoBrackets(), | 775 request_->url.HostNoBrackets(), |
787 request_->url.EffectiveIntPort(), | 776 request_->url.EffectiveIntPort(), |
788 request_->priority, request_->referrer); | 777 request_->priority, request_->referrer); |
(...skipping 30 matching lines...) Expand all Loading... |
819 // Set the reused_socket_ flag to indicate that we are using a keep-alive | 808 // Set the reused_socket_ flag to indicate that we are using a keep-alive |
820 // connection. This flag is used to handle errors that occur while we are | 809 // connection. This flag is used to handle errors that occur while we are |
821 // trying to reuse a keep-alive connection. | 810 // trying to reuse a keep-alive connection. |
822 reused_socket_ = connection_->is_reused(); | 811 reused_socket_ = connection_->is_reused(); |
823 if (reused_socket_) { | 812 if (reused_socket_) { |
824 next_state_ = STATE_SEND_REQUEST; | 813 next_state_ = STATE_SEND_REQUEST; |
825 } else { | 814 } else { |
826 // Now we have a TCP connected socket. Perform other connection setup as | 815 // Now we have a TCP connected socket. Perform other connection setup as |
827 // needed. | 816 // needed. |
828 UpdateConnectionTypeHistograms(CONNECTION_HTTP); | 817 UpdateConnectionTypeHistograms(CONNECTION_HTTP); |
829 if (using_ssl_ && (proxy_mode_ == kDirectConnection || | 818 if (using_ssl_ && (proxy_info_.is_direct() || proxy_info_.is_socks())) { |
830 proxy_mode_ == kSOCKSProxy)) { | |
831 next_state_ = STATE_SSL_CONNECT; | 819 next_state_ = STATE_SSL_CONNECT; |
832 } else { | 820 } else { |
833 next_state_ = STATE_SEND_REQUEST; | 821 next_state_ = STATE_SEND_REQUEST; |
834 if (proxy_mode_ == kHTTPProxyUsingTunnel) | 822 if (using_ssl_) |
835 establishing_tunnel_ = true; | 823 establishing_tunnel_ = true; |
836 } | 824 } |
837 } | 825 } |
838 | 826 |
839 return OK; | 827 return OK; |
840 } | 828 } |
841 | 829 |
842 int HttpNetworkTransaction::DoSSLConnect() { | 830 int HttpNetworkTransaction::DoSSLConnect() { |
843 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 831 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
844 | 832 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 if (have_proxy_auth) | 950 if (have_proxy_auth) |
963 AddAuthorizationHeader(HttpAuth::AUTH_PROXY, &authorization_headers); | 951 AddAuthorizationHeader(HttpAuth::AUTH_PROXY, &authorization_headers); |
964 if (have_server_auth) | 952 if (have_server_auth) |
965 AddAuthorizationHeader(HttpAuth::AUTH_SERVER, &authorization_headers); | 953 AddAuthorizationHeader(HttpAuth::AUTH_SERVER, &authorization_headers); |
966 | 954 |
967 if (establishing_tunnel_) { | 955 if (establishing_tunnel_) { |
968 BuildTunnelRequest(request_, authorization_headers, &request_line, | 956 BuildTunnelRequest(request_, authorization_headers, &request_line, |
969 &request_headers); | 957 &request_headers); |
970 } else { | 958 } else { |
971 BuildRequestHeaders(request_, authorization_headers, request_body, | 959 BuildRequestHeaders(request_, authorization_headers, request_body, |
972 proxy_mode_ == kHTTPProxy, &request_line, | 960 !using_ssl_ && proxy_info_.is_http(), &request_line, |
973 &request_headers); | 961 &request_headers); |
974 } | 962 } |
975 | 963 |
976 request_headers_ = request_line + request_headers.ToString(); | 964 request_headers_ = request_line + request_headers.ToString(); |
977 } | 965 } |
978 | 966 |
979 headers_valid_ = false; | 967 headers_valid_ = false; |
980 http_stream_.reset(new HttpBasicStream(connection_.get(), net_log_)); | 968 http_stream_.reset(new HttpBasicStream(connection_.get(), net_log_)); |
981 | 969 |
982 return http_stream_->SendRequest(request_, request_headers_, | 970 return http_stream_->SendRequest(request_, request_headers_, |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 // there was nothing left to fall-back to, so fail the transaction | 1657 // there was nothing left to fall-back to, so fail the transaction |
1670 // with the last connection error we got. | 1658 // with the last connection error we got. |
1671 // TODO(eroman): This is a confusing contract, make it more obvious. | 1659 // TODO(eroman): This is a confusing contract, make it more obvious. |
1672 rv = error; | 1660 rv = error; |
1673 } | 1661 } |
1674 | 1662 |
1675 return rv; | 1663 return rv; |
1676 } | 1664 } |
1677 | 1665 |
1678 bool HttpNetworkTransaction::ShouldApplyProxyAuth() const { | 1666 bool HttpNetworkTransaction::ShouldApplyProxyAuth() const { |
1679 return (proxy_mode_ == kHTTPProxy) || establishing_tunnel_; | 1667 return (!using_ssl_ && proxy_info_.is_http()) || establishing_tunnel_; |
1680 } | 1668 } |
1681 | 1669 |
1682 bool HttpNetworkTransaction::ShouldApplyServerAuth() const { | 1670 bool HttpNetworkTransaction::ShouldApplyServerAuth() const { |
1683 return !establishing_tunnel_ && | 1671 return !establishing_tunnel_ && |
1684 !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA); | 1672 !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA); |
1685 } | 1673 } |
1686 | 1674 |
1687 void HttpNetworkTransaction::AddAuthorizationHeader( | 1675 void HttpNetworkTransaction::AddAuthorizationHeader( |
1688 HttpAuth::Target target, HttpRequestHeaders* authorization_headers) const { | 1676 HttpAuth::Target target, HttpRequestHeaders* authorization_headers) const { |
1689 DCHECK(HaveAuth(target)); | 1677 DCHECK(HaveAuth(target)); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 http_host_port_pair); | 1979 http_host_port_pair); |
1992 | 1980 |
1993 alternate_protocol_mode_ = kDoNotUseAlternateProtocol; | 1981 alternate_protocol_mode_ = kDoNotUseAlternateProtocol; |
1994 if (connection_->socket()) | 1982 if (connection_->socket()) |
1995 connection_->socket()->Disconnect(); | 1983 connection_->socket()->Disconnect(); |
1996 connection_->Reset(); | 1984 connection_->Reset(); |
1997 next_state_ = STATE_INIT_CONNECTION; | 1985 next_state_ = STATE_INIT_CONNECTION; |
1998 } | 1986 } |
1999 | 1987 |
2000 } // namespace net | 1988 } // namespace net |
OLD | NEW |