Chromium Code Reviews| 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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 | 694 |
| 695 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 695 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 696 | 696 |
| 697 using_ssl_ = request_->url.SchemeIs("https"); | 697 using_ssl_ = request_->url.SchemeIs("https"); |
| 698 using_spdy_ = false; | 698 using_spdy_ = false; |
| 699 | 699 |
| 700 // Build the string used to uniquely identify connections of this type. | 700 // Build the string used to uniquely identify connections of this type. |
| 701 // Determine the host and port to connect to. | 701 // Determine the host and port to connect to. |
| 702 std::string connection_group; | 702 std::string connection_group; |
| 703 | 703 |
| 704 // |endpoint| indicates the final destination endpoint. | 704 // |endpoint_| indicates the final destination endpoint. |
| 705 HostPortPair endpoint; | 705 endpoint_ = HostPortPair(request_->url.HostNoBrackets(), |
| 706 endpoint.host = request_->url.HostNoBrackets(); | 706 request_->url.EffectiveIntPort()); |
| 707 endpoint.port = request_->url.EffectiveIntPort(); | |
| 708 | 707 |
| 709 if (!proxy_info_.is_direct()) { | 708 if (proxy_info_.is_direct()) { |
| 710 ProxyServer proxy_server = proxy_info_.proxy_server(); | |
| 711 connection_group = "proxy/" + proxy_server.ToURI() + "/"; | |
| 712 peer_.host = proxy_server.HostNoBrackets(); | |
| 713 peer_.port = proxy_server.port(); | |
| 714 } else { | |
| 715 peer_ = endpoint; | |
| 716 if (alternate_protocol_mode_ == kUnspecified) { | 709 if (alternate_protocol_mode_ == kUnspecified) { |
| 717 const HttpAlternateProtocols& alternate_protocols = | 710 const HttpAlternateProtocols& alternate_protocols = |
| 718 session_->alternate_protocols(); | 711 session_->alternate_protocols(); |
| 719 if (alternate_protocols.HasAlternateProtocolFor(peer_)) { | 712 if (alternate_protocols.HasAlternateProtocolFor(endpoint_)) { |
| 720 HttpAlternateProtocols::PortProtocolPair alternate = | 713 HttpAlternateProtocols::PortProtocolPair alternate = |
| 721 alternate_protocols.GetAlternateProtocolFor(peer_); | 714 alternate_protocols.GetAlternateProtocolFor(endpoint_); |
| 722 if (alternate.protocol != HttpAlternateProtocols::BROKEN) { | 715 if (alternate.protocol != HttpAlternateProtocols::BROKEN) { |
| 723 DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); | 716 DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); |
| 724 peer_.port = alternate.port; | 717 endpoint_.port = alternate.port; |
| 725 using_ssl_ = true; | 718 using_ssl_ = true; |
| 726 alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1; | 719 alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1; |
| 727 alternate_protocol_mode_ = kUsingAlternateProtocol; | 720 alternate_protocol_mode_ = kUsingAlternateProtocol; |
| 728 } | 721 } |
| 729 } | 722 } |
| 730 } | 723 } |
| 731 } | 724 } |
| 732 | 725 |
| 733 // Use the fixed testing ports if they've been provided. | 726 // Use the fixed testing ports if they've been provided. |
| 734 if (using_ssl_) { | 727 if (using_ssl_) { |
| 735 if (session_->fixed_https_port() != 0) | 728 if (session_->fixed_https_port() != 0) |
| 736 peer_.port = session_->fixed_https_port(); | 729 endpoint_.port = session_->fixed_https_port(); |
| 737 } else if (session_->fixed_http_port() != 0) { | 730 } else if (session_->fixed_http_port() != 0) { |
| 738 peer_.port = session_->fixed_http_port(); | 731 endpoint_.port = session_->fixed_http_port(); |
| 739 } | 732 } |
| 740 | 733 |
| 741 // Check first if we have a spdy session for this group. If so, then go | 734 // Check first if we have a spdy session for this group. If so, then go |
| 742 // straight to using that. | 735 // straight to using that. |
| 743 if (session_->spdy_session_pool()->HasSession(peer_)) { | 736 if (session_->spdy_session_pool()->HasSession(endpoint_)) { |
| 744 using_spdy_ = true; | 737 using_spdy_ = true; |
| 745 return OK; | 738 return OK; |
| 746 } | 739 } |
| 747 | 740 |
| 748 // For a connection via HTTP proxy not using CONNECT, the connection | 741 connection_group = endpoint_.ToString(); |
| 749 // is to the proxy server only. For all other cases | |
| 750 // (direct, HTTP proxy CONNECT, SOCKS), the connection is up to the | |
| 751 // url endpoint. Hence we append the url data into the connection_group. | |
| 752 // Note that the url endpoint may be different in the Alternate-Protocol case. | |
| 753 if (proxy_info_.is_direct()) | |
| 754 connection_group = peer_.ToString(); | |
| 755 else if (using_ssl_ || proxy_info_.is_socks()) | |
| 756 connection_group.append(endpoint.ToString()); | |
| 757 | |
| 758 DCHECK(!connection_group.empty()); | 742 DCHECK(!connection_group.empty()); |
| 759 | 743 |
| 760 // If the user is refreshing the page, bypass the host cache. | 744 // If the user is refreshing the page, bypass the host cache. |
| 761 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || | 745 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || |
| 762 request_->load_flags & LOAD_DISABLE_CACHE; | 746 request_->load_flags & LOAD_DISABLE_CACHE; |
| 763 | 747 |
| 764 TCPSocketParams tcp_params(peer_.host, peer_.port, request_->priority, | 748 int rv; |
| 765 request_->referrer, disable_resolver_cache); | 749 if (!proxy_info_.is_direct()) { |
|
wtc
2010/05/03 19:01:53
Nit: I prefer
if (condition) {
A;
}
| |
| 750 ProxyServer proxy_server = proxy_info_.proxy_server(); | |
| 751 HostPortPair proxy_host_port_pair(proxy_server.HostNoBrackets(), | |
| 752 proxy_server.port()); | |
| 766 | 753 |
| 767 int rv; | 754 TCPSocketParams tcp_params(proxy_host_port_pair, request_->priority, |
| 768 if (!proxy_info_.is_socks()) { | 755 request_->referrer, disable_resolver_cache); |
| 756 | |
| 757 if (proxy_info_.is_socks()) { | |
| 758 const char* socks_version; | |
| 759 bool socks_v5; | |
| 760 if (proxy_info_.proxy_server().scheme() == ProxyServer::SCHEME_SOCKS5) { | |
| 761 socks_version = "5"; | |
| 762 socks_v5 = true; | |
| 763 } else { | |
| 764 socks_version = "4"; | |
| 765 socks_v5 = false; | |
| 766 } | |
| 767 | |
| 768 connection_group = | |
| 769 StringPrintf("socks%s/%s", socks_version, connection_group.c_str()); | |
|
wtc
2010/05/03 19:01:53
Should we also add a "http/" prefix to the connect
| |
| 770 | |
| 771 SOCKSSocketParams socks_params(tcp_params, socks_v5, endpoint_, | |
| 772 request_->priority, request_->referrer); | |
| 773 | |
| 774 rv = connection_->Init( | |
| 775 connection_group, socks_params, request_->priority, | |
| 776 &io_callback_, | |
| 777 session_->GetSocketPoolForSOCKSProxy(proxy_host_port_pair), net_log_); | |
| 778 } else { | |
| 779 rv = connection_->Init( | |
| 780 connection_group, tcp_params, request_->priority, | |
| 781 &io_callback_, | |
| 782 session_->GetSocketPoolForHTTPProxy(proxy_host_port_pair), net_log_); | |
| 783 } | |
| 784 } else { | |
| 785 TCPSocketParams tcp_params(endpoint_, request_->priority, | |
| 786 request_->referrer, disable_resolver_cache); | |
| 769 rv = connection_->Init(connection_group, tcp_params, request_->priority, | 787 rv = connection_->Init(connection_group, tcp_params, request_->priority, |
| 770 &io_callback_, session_->tcp_socket_pool(), | 788 &io_callback_, session_->tcp_socket_pool(), |
| 771 net_log_); | 789 net_log_); |
| 772 } else { | |
| 773 bool socks_v5 = proxy_info_.proxy_server().scheme() == | |
| 774 ProxyServer::SCHEME_SOCKS5; | |
| 775 SOCKSSocketParams socks_params(tcp_params, socks_v5, | |
| 776 request_->url.HostNoBrackets(), | |
| 777 request_->url.EffectiveIntPort(), | |
| 778 request_->priority, request_->referrer); | |
| 779 | |
| 780 rv = connection_->Init(connection_group, socks_params, request_->priority, | |
| 781 &io_callback_, session_->socks_socket_pool(), | |
| 782 net_log_); | |
| 783 } | 790 } |
| 784 | 791 |
| 785 return rv; | 792 return rv; |
| 786 } | 793 } |
| 787 | 794 |
| 788 int HttpNetworkTransaction::DoInitConnectionComplete(int result) { | 795 int HttpNetworkTransaction::DoInitConnectionComplete(int result) { |
| 789 if (result < 0) { | 796 if (result < 0) { |
| 790 if (alternate_protocol_mode_ == kUsingAlternateProtocol) { | 797 if (alternate_protocol_mode_ == kUsingAlternateProtocol) { |
| 791 // Mark the alternate protocol as broken and fallback. | 798 // Mark the alternate protocol as broken and fallback. |
| 792 MarkBrokenAlternateProtocolAndFallback(); | 799 MarkBrokenAlternateProtocolAndFallback(); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 CHECK(!spdy_stream_.get()); | 1248 CHECK(!spdy_stream_.get()); |
| 1242 | 1249 |
| 1243 // First we get a SPDY session. Theoretically, we've just negotiated one, but | 1250 // First we get a SPDY session. Theoretically, we've just negotiated one, but |
| 1244 // if one already exists, then screw it, use the existing one! Otherwise, | 1251 // if one already exists, then screw it, use the existing one! Otherwise, |
| 1245 // use the existing TCP socket. | 1252 // use the existing TCP socket. |
| 1246 | 1253 |
| 1247 const scoped_refptr<SpdySessionPool> spdy_pool = | 1254 const scoped_refptr<SpdySessionPool> spdy_pool = |
| 1248 session_->spdy_session_pool(); | 1255 session_->spdy_session_pool(); |
| 1249 scoped_refptr<SpdySession> spdy_session; | 1256 scoped_refptr<SpdySession> spdy_session; |
| 1250 | 1257 |
| 1251 if (spdy_pool->HasSession(peer_)) { | 1258 if (spdy_pool->HasSession(endpoint_)) { |
| 1252 spdy_session = spdy_pool->Get(peer_, session_); | 1259 spdy_session = spdy_pool->Get(endpoint_, session_); |
| 1253 } else { | 1260 } else { |
| 1254 // SPDY is negotiated using the TLS next protocol negotiation (NPN) | 1261 // SPDY is negotiated using the TLS next protocol negotiation (NPN) |
| 1255 // extension, so |connection_| must contain an SSLClientSocket. | 1262 // extension, so |connection_| must contain an SSLClientSocket. |
| 1256 DCHECK(using_ssl_); | 1263 DCHECK(using_ssl_); |
| 1257 CHECK(connection_->socket()); | 1264 CHECK(connection_->socket()); |
| 1258 spdy_session = spdy_pool->GetSpdySessionFromSSLSocket( | 1265 spdy_session = spdy_pool->GetSpdySessionFromSSLSocket( |
| 1259 peer_, session_, connection_.release()); | 1266 endpoint_, session_, connection_.release()); |
| 1260 } | 1267 } |
| 1261 | 1268 |
| 1262 CHECK(spdy_session.get()); | 1269 CHECK(spdy_session.get()); |
| 1263 | 1270 |
| 1264 UploadDataStream* upload_data = NULL; | 1271 UploadDataStream* upload_data = NULL; |
| 1265 if (request_->upload_data) { | 1272 if (request_->upload_data) { |
| 1266 int error_code = OK; | 1273 int error_code = OK; |
| 1267 upload_data = UploadDataStream::Create(request_->upload_data, &error_code); | 1274 upload_data = UploadDataStream::Create(request_->upload_data, &error_code); |
| 1268 if (!upload_data) | 1275 if (!upload_data) |
| 1269 return error_code; | 1276 return error_code; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1980 http_host_port_pair); | 1987 http_host_port_pair); |
| 1981 | 1988 |
| 1982 alternate_protocol_mode_ = kDoNotUseAlternateProtocol; | 1989 alternate_protocol_mode_ = kDoNotUseAlternateProtocol; |
| 1983 if (connection_->socket()) | 1990 if (connection_->socket()) |
| 1984 connection_->socket()->Disconnect(); | 1991 connection_->socket()->Disconnect(); |
| 1985 connection_->Reset(); | 1992 connection_->Reset(); |
| 1986 next_state_ = STATE_INIT_CONNECTION; | 1993 next_state_ = STATE_INIT_CONNECTION; |
| 1987 } | 1994 } |
| 1988 | 1995 |
| 1989 } // namespace net | 1996 } // namespace net |
| OLD | NEW |