diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 18:06:06 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 18:06:06 +0000 |
commit | 31e2c69eb9a9cf4e59f08b483f7cd849631e7da4 (patch) | |
tree | b3aa94737e007c402e16f761af2c8b11796a360c | |
parent | 485392bfbc7a311782c2663b02f28a64f1bcc4be (diff) | |
download | chromium_src-31e2c69eb9a9cf4e59f08b483f7cd849631e7da4.zip chromium_src-31e2c69eb9a9cf4e59f08b483f7cd849631e7da4.tar.gz chromium_src-31e2c69eb9a9cf4e59f08b483f7cd849631e7da4.tar.bz2 |
SPDY: Alternate-Protocol changes.
Change chromium to expect npn-spdy/1 instead of npn-spdy to match server-side changes.
Move the use of Alternate-Protocol to be behind command line flag: "--use-alternate-protocols".
Review URL: http://codereview.chromium.org/1593029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44663 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | net/http/http_alternate_protocols.cc | 2 | ||||
-rw-r--r-- | net/http/http_alternate_protocols.h | 2 | ||||
-rw-r--r-- | net/http/http_alternate_protocols_unittest.cc | 9 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 24 | ||||
-rw-r--r-- | net/http/http_network_transaction.h | 3 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 16 |
9 files changed, 43 insertions, 20 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 17838223..840c0d1 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -363,6 +363,9 @@ void InitializeNetworkOptions(const CommandLine& parsed_command_line) { if (parsed_command_line.HasSwitch(switches::kIgnoreCertificateErrors)) net::HttpNetworkTransaction::IgnoreCertificateErrors(true); + if (parsed_command_line.HasSwitch(switches::kUseAlternateProtocols)) + net::HttpNetworkTransaction::SetUseAlternateProtocols(true); + if (parsed_command_line.HasSwitch(switches::kMaxSpdySessionsPerDomain)) { int value = StringToInt( parsed_command_line.GetSwitchValueASCII( diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index a1725e9..d75105d 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -753,6 +753,9 @@ const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; // Set the maximum SPDY sessions per domain. const char kMaxSpdySessionsPerDomain[] = "max-spdy-sessions-per-domain"; +// Enable Alternate-Protocol support. +const char kUseAlternateProtocols[] = "use-alternate-protocols"; + // Use the low fragmentation heap for the CRT. const char kUseLowFragHeapCrt[] = "use-lf-heap"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index ca48aa7..7cf55b3 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -211,6 +211,7 @@ extern const char kFixedHttpPort[]; extern const char kFixedHttpsPort[]; extern const char kIgnoreCertificateErrors[]; extern const char kMaxSpdySessionsPerDomain[]; +extern const char kUseAlternateProtocols[]; extern const char kUseLowFragHeapCrt[]; extern const char kUserAgent[]; extern const char kUserDataDir[]; diff --git a/net/http/http_alternate_protocols.cc b/net/http/http_alternate_protocols.cc index a945917..cd42ed5 100644 --- a/net/http/http_alternate_protocols.cc +++ b/net/http/http_alternate_protocols.cc @@ -11,7 +11,7 @@ namespace net { const char HttpAlternateProtocols::kHeader[] = "Alternate-Protocol"; const char* const HttpAlternateProtocols::kProtocolStrings[] = { - "npn-spdy", + "npn-spdy/1", }; HttpAlternateProtocols::HttpAlternateProtocols() {} diff --git a/net/http/http_alternate_protocols.h b/net/http/http_alternate_protocols.h index a6ccab33..56fb49a 100644 --- a/net/http/http_alternate_protocols.h +++ b/net/http/http_alternate_protocols.h @@ -19,7 +19,7 @@ namespace net { class HttpAlternateProtocols { public: enum Protocol { - NPN_SPDY, + NPN_SPDY_1, NUM_ALTERNATE_PROTOCOLS, BROKEN, // The alternate protocol is known to be broken. }; diff --git a/net/http/http_alternate_protocols_unittest.cc b/net/http/http_alternate_protocols_unittest.cc index 7f94534..f725fc0 100644 --- a/net/http/http_alternate_protocols_unittest.cc +++ b/net/http/http_alternate_protocols_unittest.cc @@ -19,14 +19,13 @@ TEST(HttpAlternateProtocols, Basic) { test_host_port_pair.port = 80; EXPECT_FALSE( alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); - alternate_protocols.SetAlternateProtocolFor(test_host_port_pair, - 443, - HttpAlternateProtocols::NPN_SPDY); + alternate_protocols.SetAlternateProtocolFor( + test_host_port_pair, 443, HttpAlternateProtocols::NPN_SPDY_1); ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); const HttpAlternateProtocols::PortProtocolPair alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); EXPECT_EQ(443, alternate.port); - EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY, alternate.protocol); + EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); } TEST(HttpAlternateProtocols, SetBroken) { @@ -43,7 +42,7 @@ TEST(HttpAlternateProtocols, SetBroken) { alternate_protocols.SetAlternateProtocolFor( test_host_port_pair, 1234, - HttpAlternateProtocols::NPN_SPDY), + HttpAlternateProtocols::NPN_SPDY_1), alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol) << "Second attempt should be ignored."; diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 9078f35..f66cd7d 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -46,6 +46,7 @@ namespace net { namespace { const std::string* g_next_protos = NULL; +bool g_use_alternate_protocols = false; void BuildRequestHeaders(const HttpRequestInfo* request_info, const HttpRequestHeaders& authorization_headers, @@ -160,7 +161,7 @@ void ProcessAlternateProtocol(const HttpResponseHeaders& headers, const HostPortPair& http_host_port_pair, HttpAlternateProtocols* alternate_protocols) { if (!g_next_protos || g_next_protos->empty()) { - // This implies that NPN is not suppoted. We don't currently support any + // This implies that NPN is not supported. We don't currently support any // alternate protocols that don't use NPN. return; } @@ -192,7 +193,7 @@ void ProcessAlternateProtocol(const HttpResponseHeaders& headers, if (port_protocol_vector[1] != HttpAlternateProtocols::kProtocolStrings[ - HttpAlternateProtocols::NPN_SPDY]) { + HttpAlternateProtocols::NPN_SPDY_1]) { // Currently, we only recognize the npn-spdy protocol. DLOG(WARNING) << HttpAlternateProtocols::kHeader << " header has unrecognized protocol: " @@ -209,7 +210,7 @@ void ProcessAlternateProtocol(const HttpResponseHeaders& headers, } alternate_protocols->SetAlternateProtocolFor( - http_host_port_pair, port, HttpAlternateProtocols::NPN_SPDY); + http_host_port_pair, port, HttpAlternateProtocols::NPN_SPDY_1); } } // namespace @@ -234,7 +235,9 @@ HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) proxy_mode_(kDirectConnection), establishing_tunnel_(false), using_spdy_(false), - alternate_protocol_mode_(kUnspecified), + alternate_protocol_mode_( + g_use_alternate_protocols ? kUnspecified : + kDoNotUseAlternateProtocol), embedded_identity_used_(false), default_credentials_used_(false), read_buf_len_(0), @@ -245,6 +248,11 @@ HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) } // static +void HttpNetworkTransaction::SetUseAlternateProtocols(bool value) { + g_use_alternate_protocols = value; +} + +// static void HttpNetworkTransaction::SetNextProtos(const std::string& next_protos) { delete g_next_protos; g_next_protos = new std::string(next_protos); @@ -723,10 +731,10 @@ int HttpNetworkTransaction::DoInitConnection() { HttpAlternateProtocols::PortProtocolPair alternate = alternate_protocols.GetAlternateProtocolFor(host, port); if (alternate.protocol != HttpAlternateProtocols::BROKEN) { - DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY, alternate.protocol); + DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); port = alternate.port; using_ssl_ = true; - alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY; + alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1; alternate_protocol_mode_ = kUsingAlternateProtocol; } } @@ -863,9 +871,9 @@ int HttpNetworkTransaction::DoSSLConnectComplete(int result) { proto == kSpdyProto); if (alternate_protocol_mode_ == kUsingAlternateProtocol && - alternate_protocol_ == HttpAlternateProtocols::NPN_SPDY && + alternate_protocol_ == HttpAlternateProtocols::NPN_SPDY_1 && !using_spdy_) { - // We tried using the NPN_SPDY alternate protocol, but failed, so we + // We tried using the NPN_SPDY_1 alternate protocol, but failed, so we // fallback. MarkBrokenAlternateProtocolAndFallback(); return OK; diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index 220e789..ed5ff75 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -42,6 +42,9 @@ class HttpNetworkTransaction : public HttpTransaction { virtual ~HttpNetworkTransaction(); + // Controls whether or not we use the Alternate-Protocol header. + static void SetUseAlternateProtocols(bool value); + // Sets the next protocol negotiation value used during the SSL handshake. static void SetNextProtos(const std::string& next_protos); diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index b9458d5..df1604e 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -4454,12 +4454,13 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { HttpNetworkTransaction::SetNextProtos("needs_to_be_set_for_this_test"); + HttpNetworkTransaction::SetUseAlternateProtocols(true); SessionDependencies session_deps; MockRead data_reads[] = { MockRead("HTTP/1.1 200 OK\r\n"), - MockRead("Alternate-Protocol: 443:npn-spdy\r\n\r\n"), + MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), MockRead("hello world"), MockRead(false, OK), }; @@ -4505,13 +4506,15 @@ TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { alternate_protocols.GetAlternateProtocolFor(http_host_port_pair); HttpAlternateProtocols::PortProtocolPair expected_alternate; expected_alternate.port = 443; - expected_alternate.protocol = HttpAlternateProtocols::NPN_SPDY; + expected_alternate.protocol = HttpAlternateProtocols::NPN_SPDY_1; EXPECT_TRUE(expected_alternate.Equals(alternate)); + HttpNetworkTransaction::SetUseAlternateProtocols(false); HttpNetworkTransaction::SetNextProtos(""); } TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) { + HttpNetworkTransaction::SetUseAlternateProtocols(true); SessionDependencies session_deps; HttpRequestInfo request; @@ -4549,7 +4552,7 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) { session->mutable_alternate_protocols(); alternate_protocols->SetAlternateProtocolFor( http_host_port_pair, 1234 /* port is ignored by MockConnect anyway */, - HttpAlternateProtocols::NPN_SPDY); + HttpAlternateProtocols::NPN_SPDY_1); scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); @@ -4571,6 +4574,7 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) { const HttpAlternateProtocols::PortProtocolPair alternate = alternate_protocols->GetAlternateProtocolFor(http_host_port_pair); EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol); + HttpNetworkTransaction::SetUseAlternateProtocols(false); } // TODO(willchan): Redo this test to use TLS/NPN=>SPDY. Currently, the code @@ -4608,7 +4612,7 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) { // session->mutable_alternate_protocols(); // alternate_protocols->SetAlternateProtocolFor( // http_host_port_pair, 1234 /* port is ignored */, -// HttpAlternateProtocols::NPN_SPDY); +// HttpAlternateProtocols::NPN_SPDY_1); // // scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); // @@ -4627,6 +4631,7 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) { // } TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { + HttpNetworkTransaction::SetUseAlternateProtocols(true); SessionDependencies session_deps; HttpRequestInfo request; @@ -4660,7 +4665,7 @@ TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { session->mutable_alternate_protocols(); alternate_protocols->SetAlternateProtocolFor( http_host_port_pair, 1234 /* port is ignored */, - HttpAlternateProtocols::NPN_SPDY); + HttpAlternateProtocols::NPN_SPDY_1); scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); @@ -4676,6 +4681,7 @@ TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { std::string response_data; ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello world", response_data); + HttpNetworkTransaction::SetUseAlternateProtocols(false); } // MockAuthHandlerCanonical is used by the ResolveCanonicalName |