Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: net/http/http_network_transaction.cc

Issue 1755005: SPDY: Fix Alternate-Protocol. (Closed)
Patch Set: Address mbelshe's comments. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 else if (proxy_info_.proxy_server().is_socks()) 703 else if (proxy_info_.proxy_server().is_socks())
704 proxy_mode_ = kSOCKSProxy; 704 proxy_mode_ = kSOCKSProxy;
705 else if (using_ssl_) 705 else if (using_ssl_)
706 proxy_mode_ = kHTTPProxyUsingTunnel; 706 proxy_mode_ = kHTTPProxyUsingTunnel;
707 else 707 else
708 proxy_mode_ = kHTTPProxy; 708 proxy_mode_ = kHTTPProxy;
709 709
710 // Build the string used to uniquely identify connections of this type. 710 // Build the string used to uniquely identify connections of this type.
711 // Determine the host and port to connect to. 711 // Determine the host and port to connect to.
712 std::string connection_group; 712 std::string connection_group;
713 std::string host; 713
714 int port; 714 // |endpoint| indicates the final destination endpoint.
715 HostPortPair endpoint;
716 endpoint.host = request_->url.HostNoBrackets();
717 endpoint.port = request_->url.EffectiveIntPort();
718
715 if (proxy_mode_ != kDirectConnection) { 719 if (proxy_mode_ != kDirectConnection) {
716 ProxyServer proxy_server = proxy_info_.proxy_server(); 720 ProxyServer proxy_server = proxy_info_.proxy_server();
717 connection_group = "proxy/" + proxy_server.ToURI() + "/"; 721 connection_group = "proxy/" + proxy_server.ToURI() + "/";
718 host = proxy_server.HostNoBrackets(); 722 peer_.host = proxy_server.HostNoBrackets();
719 port = proxy_server.port(); 723 peer_.port = proxy_server.port();
720 } else { 724 } else {
721 host = request_->url.HostNoBrackets(); 725 peer_ = endpoint;
722 port = request_->url.EffectiveIntPort();
723 if (alternate_protocol_mode_ == kUnspecified) { 726 if (alternate_protocol_mode_ == kUnspecified) {
724 const HttpAlternateProtocols& alternate_protocols = 727 const HttpAlternateProtocols& alternate_protocols =
725 session_->alternate_protocols(); 728 session_->alternate_protocols();
726 if (alternate_protocols.HasAlternateProtocolFor(host, port)) { 729 if (alternate_protocols.HasAlternateProtocolFor(peer_)) {
727 HttpAlternateProtocols::PortProtocolPair alternate = 730 HttpAlternateProtocols::PortProtocolPair alternate =
728 alternate_protocols.GetAlternateProtocolFor(host, port); 731 alternate_protocols.GetAlternateProtocolFor(peer_);
729 if (alternate.protocol != HttpAlternateProtocols::BROKEN) { 732 if (alternate.protocol != HttpAlternateProtocols::BROKEN) {
730 DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); 733 DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol);
731 port = alternate.port; 734 peer_.port = alternate.port;
732 using_ssl_ = true; 735 using_ssl_ = true;
733 alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1; 736 alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1;
734 alternate_protocol_mode_ = kUsingAlternateProtocol; 737 alternate_protocol_mode_ = kUsingAlternateProtocol;
735 } 738 }
736 } 739 }
737 } 740 }
738 } 741 }
739 742
740 // Use the fixed testing ports if they've been provided. 743 // Use the fixed testing ports if they've been provided.
741 if (using_ssl_) { 744 if (using_ssl_) {
742 if (session_->fixed_https_port() != 0) 745 if (session_->fixed_https_port() != 0)
743 port = session_->fixed_https_port(); 746 peer_.port = session_->fixed_https_port();
744 } else if (session_->fixed_http_port() != 0) { 747 } else if (session_->fixed_http_port() != 0) {
745 port = session_->fixed_http_port(); 748 peer_.port = session_->fixed_http_port();
746 } 749 }
747 750
748 // Check first if we have a spdy session for this group. If so, then go 751 // Check first if we have a spdy session for this group. If so, then go
749 // straight to using that. 752 // straight to using that.
750 HostPortPair host_port_pair(host, port); 753 if (session_->spdy_session_pool()->HasSession(peer_)) {
751 if (session_->spdy_session_pool()->HasSession(host_port_pair)) {
752 using_spdy_ = true; 754 using_spdy_ = true;
753 return OK; 755 return OK;
754 } 756 }
755 757
756 // For a connection via HTTP proxy not using CONNECT, the connection 758 // For a connection via HTTP proxy not using CONNECT, the connection
757 // is to the proxy server only. For all other cases 759 // is to the proxy server only. For all other cases
758 // (direct, HTTP proxy CONNECT, SOCKS), the connection is upto the 760 // (direct, HTTP proxy CONNECT, SOCKS), the connection is up to the
759 // url endpoint. Hence we append the url data into the connection_group. 761 // url endpoint. Hence we append the url data into the connection_group.
760 if (proxy_mode_ != kHTTPProxy) 762 // Note that the url endpoint may be different in the Alternate-Protocol case.
761 connection_group.append(request_->url.GetOrigin().spec()); 763 if (proxy_mode_ == kDirectConnection)
764 connection_group = peer_.ToString();
765 else if (proxy_mode_ != kHTTPProxy)
766 connection_group.append(endpoint.ToString());
762 767
763 DCHECK(!connection_group.empty()); 768 DCHECK(!connection_group.empty());
764 769
765 // If the user is refreshing the page, bypass the host cache. 770 // If the user is refreshing the page, bypass the host cache.
766 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE || 771 bool disable_resolver_cache = request_->load_flags & LOAD_BYPASS_CACHE ||
767 request_->load_flags & LOAD_DISABLE_CACHE; 772 request_->load_flags & LOAD_DISABLE_CACHE;
768 773
769 TCPSocketParams tcp_params(host, port, request_->priority, request_->referrer, 774 TCPSocketParams tcp_params(peer_.host, peer_.port, request_->priority,
770 disable_resolver_cache); 775 request_->referrer, disable_resolver_cache);
771 776
772 int rv; 777 int rv;
773 if (proxy_mode_ != kSOCKSProxy) { 778 if (proxy_mode_ != kSOCKSProxy) {
774 rv = connection_->Init(connection_group, tcp_params, request_->priority, 779 rv = connection_->Init(connection_group, tcp_params, request_->priority,
775 &io_callback_, session_->tcp_socket_pool(), 780 &io_callback_, session_->tcp_socket_pool(),
776 net_log_); 781 net_log_);
777 } else { 782 } else {
778 bool socks_v5 = proxy_info_.proxy_server().scheme() == 783 bool socks_v5 = proxy_info_.proxy_server().scheme() ==
779 ProxyServer::SCHEME_SOCKS5; 784 ProxyServer::SCHEME_SOCKS5;
780 SOCKSSocketParams socks_params(tcp_params, socks_v5, 785 SOCKSSocketParams socks_params(tcp_params, socks_v5,
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 } 1248 }
1244 1249
1245 int HttpNetworkTransaction::DoSpdySendRequest() { 1250 int HttpNetworkTransaction::DoSpdySendRequest() {
1246 next_state_ = STATE_SPDY_SEND_REQUEST_COMPLETE; 1251 next_state_ = STATE_SPDY_SEND_REQUEST_COMPLETE;
1247 CHECK(!spdy_stream_.get()); 1252 CHECK(!spdy_stream_.get());
1248 1253
1249 // First we get a SPDY session. Theoretically, we've just negotiated one, but 1254 // First we get a SPDY session. Theoretically, we've just negotiated one, but
1250 // if one already exists, then screw it, use the existing one! Otherwise, 1255 // if one already exists, then screw it, use the existing one! Otherwise,
1251 // use the existing TCP socket. 1256 // use the existing TCP socket.
1252 1257
1253 HostPortPair host_port_pair(request_->url.HostNoBrackets(),
1254 request_->url.EffectiveIntPort());
1255 const scoped_refptr<SpdySessionPool> spdy_pool = 1258 const scoped_refptr<SpdySessionPool> spdy_pool =
1256 session_->spdy_session_pool(); 1259 session_->spdy_session_pool();
1257 scoped_refptr<SpdySession> spdy_session; 1260 scoped_refptr<SpdySession> spdy_session;
1258 1261
1259 if (spdy_pool->HasSession(host_port_pair)) { 1262 if (spdy_pool->HasSession(peer_)) {
1260 spdy_session = spdy_pool->Get(host_port_pair, session_); 1263 spdy_session = spdy_pool->Get(peer_, session_);
1261 } else { 1264 } else {
1262 // SPDY is negotiated using the TLS next protocol negotiation (NPN) 1265 // SPDY is negotiated using the TLS next protocol negotiation (NPN)
1263 // extension, so |connection_| must contain an SSLClientSocket. 1266 // extension, so |connection_| must contain an SSLClientSocket.
1264 DCHECK(using_ssl_); 1267 DCHECK(using_ssl_);
1268 CHECK(connection_->socket());
1265 spdy_session = spdy_pool->GetSpdySessionFromSSLSocket( 1269 spdy_session = spdy_pool->GetSpdySessionFromSSLSocket(
1266 host_port_pair, session_, connection_.release()); 1270 peer_, session_, connection_.release());
1267 } 1271 }
1268 1272
1269 CHECK(spdy_session.get()); 1273 CHECK(spdy_session.get());
1270 1274
1271 UploadDataStream* upload_data = NULL; 1275 UploadDataStream* upload_data = NULL;
1272 if (request_->upload_data) { 1276 if (request_->upload_data) {
1273 int error_code = OK; 1277 int error_code = OK;
1274 upload_data = UploadDataStream::Create(request_->upload_data, &error_code); 1278 upload_data = UploadDataStream::Create(request_->upload_data, &error_code);
1275 if (!upload_data) 1279 if (!upload_data)
1276 return error_code; 1280 return error_code;
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 http_host_port_pair); 1991 http_host_port_pair);
1988 1992
1989 alternate_protocol_mode_ = kDoNotUseAlternateProtocol; 1993 alternate_protocol_mode_ = kDoNotUseAlternateProtocol;
1990 if (connection_->socket()) 1994 if (connection_->socket())
1991 connection_->socket()->Disconnect(); 1995 connection_->socket()->Disconnect();
1992 connection_->Reset(); 1996 connection_->Reset();
1993 next_state_ = STATE_INIT_CONNECTION; 1997 next_state_ = STATE_INIT_CONNECTION;
1994 } 1998 }
1995 1999
1996 } // namespace net 2000 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698