diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 16:17:16 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 16:17:16 +0000 |
commit | 0ce3af8576117e6b83f86fdb1c9b26dc6aebaf5c (patch) | |
tree | 58e457798ff03f0c01de30d6345d76a1c5190f84 | |
parent | 94287522d76634ab3cb8c31bbec6b97e7f2e7c40 (diff) | |
download | chromium_src-0ce3af8576117e6b83f86fdb1c9b26dc6aebaf5c.zip chromium_src-0ce3af8576117e6b83f86fdb1c9b26dc6aebaf5c.tar.gz chromium_src-0ce3af8576117e6b83f86fdb1c9b26dc6aebaf5c.tar.bz2 |
Remove QUIC from NPN strings so as to save space in ALPN
advertisements. Refactor HttpStreamFactory::SetNextProtos to traffic
in enums instead of strings.
BUG=
R=akalin@chromium.org
Review URL: https://codereview.chromium.org/19696009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212894 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 31 | ||||
-rw-r--r-- | net/http/http_server_properties.cc | 23 | ||||
-rw-r--r-- | net/http/http_server_properties.h | 3 | ||||
-rw-r--r-- | net/http/http_stream_factory.cc | 82 | ||||
-rw-r--r-- | net/http/http_stream_factory.h | 2 | ||||
-rw-r--r-- | net/quic/quic_network_transaction_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.cc | 33 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_common.h | 6 |
9 files changed, 82 insertions, 102 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index e9723e6..64e0026 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -82,26 +82,6 @@ const base::string16 kSecond(ASCIIToUTF16("second")); const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); -// MakeNextProtos is a utility function that returns a vector of std::strings -// from its arguments. Don't forget to terminate the argument list with a NULL. -std::vector<std::string> MakeNextProtos(const char* a, ...) { - std::vector<std::string> ret; - ret.push_back(a); - - va_list args; - va_start(args, a); - - for (;;) { - const char* value = va_arg(args, const char*); - if (value == NULL) - break; - ret.push_back(value); - } - va_end(args); - - return ret; -} - int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { return session->GetTransportSocketPool( net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); @@ -272,7 +252,7 @@ class HttpNetworkTransactionTest NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); base::MessageLoop::current()->RunUntilIdle(); HttpStreamFactory::set_use_alternate_protocols(false); - HttpStreamFactory::SetNextProtos(std::vector<std::string>()); + HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); } // This is the expected return from a current server advertising SPDY. @@ -7977,8 +7957,6 @@ TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { expected_alternate.port = 443; expected_alternate.protocol = AlternateProtocolFromNextProto(GetParam()); EXPECT_TRUE(expected_alternate.Equals(alternate)); - - HttpStreamFactory::SetNextProtos(std::vector<std::string>()); } TEST_P(HttpNetworkTransactionTest, @@ -9480,8 +9458,9 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { // npn is negotiated. TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { HttpStreamFactory::set_use_alternate_protocols(true); - HttpStreamFactory::SetNextProtos( - MakeNextProtos("http/1.1", "http1.1", NULL)); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); + HttpStreamFactory::SetNextProtos(next_protos); HttpRequestInfo request; request.method = "GET"; request.url = GURL("https://www.google.com/"); @@ -11447,8 +11426,6 @@ TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); EXPECT_FALSE( HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); - - HttpStreamFactory::SetNextProtos(std::vector<std::string>()); } TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { diff --git a/net/http/http_server_properties.cc b/net/http/http_server_properties.cc index 069f16c..0441361 100644 --- a/net/http/http_server_properties.cc +++ b/net/http/http_server_properties.cc @@ -52,6 +52,29 @@ AlternateProtocol AlternateProtocolFromString(const std::string& protocol) { return UNINITIALIZED_ALTERNATE_PROTOCOL; } +AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { + switch (next_proto) { + case kProtoSPDY2: + return NPN_SPDY_2; + case kProtoSPDY3: + return NPN_SPDY_3; + case kProtoSPDY31: + return NPN_SPDY_3_1; + case kProtoSPDY4a2: + return NPN_SPDY_4A2; + case kProtoQUIC1SPDY3: + return QUIC; + + case kProtoUnknown: + case kProtoHTTP11: + case kProtoSPDY1: + case kProtoSPDY21: + break; + } + + NOTREACHED() << "Invalid NextProto: " << next_proto; + return UNINITIALIZED_ALTERNATE_PROTOCOL; +} std::string PortAlternateProtocolPair::ToString() const { return base::StringPrintf("%d:%s", port, diff --git a/net/http/http_server_properties.h b/net/http/http_server_properties.h index d75548a..b017a3f 100644 --- a/net/http/http_server_properties.h +++ b/net/http/http_server_properties.h @@ -12,6 +12,7 @@ #include "net/base/host_port_pair.h" #include "net/base/net_export.h" #include "net/http/http_pipelined_host_capability.h" +#include "net/socket/next_proto.h" #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this. namespace net { @@ -33,6 +34,8 @@ enum AlternateProtocol { NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol); NET_EXPORT AlternateProtocol AlternateProtocolFromString( const std::string& protocol); +NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto( + NextProto next_proto); struct NET_EXPORT PortAlternateProtocolPair { bool Equals(const PortAlternateProtocolPair& other) const { diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index 0561c34..cca445e 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -141,10 +141,10 @@ bool HttpStreamFactory::HasSpdyExclusion(const HostPortPair& endpoint) { // static void HttpStreamFactory::EnableNpnSpdy() { set_use_alternate_protocols(true); - std::vector<std::string> next_protos; - next_protos.push_back("http/1.1"); - next_protos.push_back("quic/1+spdy/3"); - next_protos.push_back("spdy/2"); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); + next_protos.push_back(kProtoQUIC1SPDY3); + next_protos.push_back(kProtoSPDY2); SetNextProtos(next_protos); } @@ -153,53 +153,53 @@ void HttpStreamFactory::EnableNpnHttpOnly() { // Avoid alternate protocol in this case. Otherwise, browser will try SSL // and then fallback to http. This introduces extra load. set_use_alternate_protocols(false); - std::vector<std::string> next_protos; - next_protos.push_back("http/1.1"); - next_protos.push_back("http1.1"); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); SetNextProtos(next_protos); } // static void HttpStreamFactory::EnableNpnSpdy3() { set_use_alternate_protocols(true); - std::vector<std::string> next_protos; - next_protos.push_back("http/1.1"); - next_protos.push_back("quic/1+spdy/3"); - next_protos.push_back("spdy/2"); - next_protos.push_back("spdy/3"); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); + next_protos.push_back(kProtoQUIC1SPDY3); + next_protos.push_back(kProtoSPDY2); + next_protos.push_back(kProtoSPDY3); SetNextProtos(next_protos); } // static void HttpStreamFactory::EnableNpnSpdy31() { set_use_alternate_protocols(true); - std::vector<std::string> next_protos; - next_protos.push_back("http/1.1"); - next_protos.push_back("quic/1+spdy/3"); - next_protos.push_back("spdy/2"); - next_protos.push_back("spdy/3"); - next_protos.push_back("spdy/3.1"); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); + next_protos.push_back(kProtoQUIC1SPDY3); + next_protos.push_back(kProtoSPDY2); + next_protos.push_back(kProtoSPDY3); + next_protos.push_back(kProtoSPDY31); SetNextProtos(next_protos); } // static void HttpStreamFactory::EnableNpnSpdy4a2() { set_use_alternate_protocols(true); - std::vector<std::string> next_protos; - next_protos.push_back("http/1.1"); - next_protos.push_back("spdy/2"); - next_protos.push_back("spdy/3"); - next_protos.push_back("spdy/3.1"); - next_protos.push_back("spdy/4a2"); + std::vector<NextProto> next_protos; + next_protos.push_back(kProtoHTTP11); + next_protos.push_back(kProtoQUIC1SPDY3); + next_protos.push_back(kProtoSPDY2); + next_protos.push_back(kProtoSPDY3); + next_protos.push_back(kProtoSPDY31); + next_protos.push_back(kProtoSPDY4a2); SetNextProtos(next_protos); } // static -void HttpStreamFactory::SetNextProtos(const std::vector<std::string>& value) { +void HttpStreamFactory::SetNextProtos(const std::vector<NextProto>& value) { if (!next_protos_) next_protos_ = new std::vector<std::string>; - *next_protos_ = value; + next_protos_->clear(); for (uint32 i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) enabled_protocols_[i] = false; @@ -207,22 +207,24 @@ void HttpStreamFactory::SetNextProtos(const std::vector<std::string>& value) { // TODO(rtenneti): bug 116575 - consider using same strings/enums for SPDY // versions in next_protos and kAlternateProtocolStrings. for (uint32 i = 0; i < value.size(); ++i) { - if (value[i] == "spdy/1") { - enabled_protocols_[NPN_SPDY_1] = true; - } else if (value[i] == "spdy/2") { - enabled_protocols_[NPN_SPDY_2] = true; - } else if (value[i] == "spdy/3") { - enabled_protocols_[NPN_SPDY_3] = true; - } else if (value[i] == "spdy/3.1") { - enabled_protocols_[NPN_SPDY_3_1] = true; - } else if (value[i] == "spdy/4a2") { - enabled_protocols_[NPN_SPDY_4A2] = true; - } else if (value[i] == "quic/1+spdy/3") { - enabled_protocols_[QUIC] = true; + NextProto proto = value[i]; + // Add the protocol to the TLS next protocol list, except for QUIC + // since it uses UDP. + if (proto != kProtoQUIC1SPDY3) { + next_protos_->push_back(SSLClientSocket::NextProtoToString(proto)); + } + + // Enable the corresponding alternate protocol, except for HTTP + // which has not corresponding alternative. + if (proto != kProtoHTTP11) { + AlternateProtocol alternate = AlternateProtocolFromNextProto(proto); + if (alternate == UNINITIALIZED_ALTERNATE_PROTOCOL) { + NOTREACHED() << "Invalid next proto: " << proto; + continue; + } + enabled_protocols_[alternate] = true; } } - // TODO(rch): Remove all support for spdy/1. - enabled_protocols_[NPN_SPDY_1] = false; } HttpStreamFactory::HttpStreamFactory() {} diff --git a/net/http/http_stream_factory.h b/net/http/http_stream_factory.h index 79ca388..bebfb8c 100644 --- a/net/http/http_stream_factory.h +++ b/net/http/http_stream_factory.h @@ -280,7 +280,7 @@ class NET_EXPORT HttpStreamFactory { // Sets the protocols supported by NPN (next protocol negotiation) during the // SSL handshake as well as by HTTP Alternate-Protocol. - static void SetNextProtos(const std::vector<std::string>& value); + static void SetNextProtos(const std::vector<NextProto>& value); static bool has_next_protos() { return next_protos_ != NULL; } static const std::vector<std::string>& next_protos() { return *next_protos_; diff --git a/net/quic/quic_network_transaction_unittest.cc b/net/quic/quic_network_transaction_unittest.cc index 4a99afc..a52b867 100644 --- a/net/quic/quic_network_transaction_unittest.cc +++ b/net/quic/quic_network_transaction_unittest.cc @@ -82,7 +82,7 @@ class QuicNetworkTransactionTest : public PlatformTest { NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); base::MessageLoop::current()->RunUntilIdle(); HttpStreamFactory::set_use_alternate_protocols(false); - HttpStreamFactory::SetNextProtos(std::vector<std::string>()); + HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); } scoped_ptr<QuicEncryptedPacket> ConstructRstPacket( diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index ba6a607..aa55dfe 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -188,7 +188,7 @@ class SpdyNetworkTransactionTest HttpStreamFactory::set_force_spdy_over_ssl(false); HttpStreamFactory::set_force_spdy_always(false); - std::vector<std::string> next_protos = SpdyNextProtos(); + std::vector<NextProto> next_protos = SpdyNextProtos(); switch (test_params_.ssl_type) { case SPDYNPN: diff --git a/net/spdy/spdy_test_util_common.cc b/net/spdy/spdy_test_util_common.cc index 2881844..84be098 100644 --- a/net/spdy/spdy_test_util_common.cc +++ b/net/spdy/spdy_test_util_common.cc @@ -51,11 +51,12 @@ void ParseUrl(base::StringPiece url, std::string* scheme, std::string* host, } // namespace -std::vector<std::string> SpdyNextProtos() { - std::vector<std::string> next_protos; +std::vector<NextProto> SpdyNextProtos() { + std::vector<NextProto> next_protos; for (int i = kProtoMinimumVersion; i <= kProtoMaximumVersion; ++i) { - next_protos.push_back(SSLClientSocket::NextProtoToString( - static_cast<NextProto>(i))); + NextProto proto = static_cast<NextProto>(i); + if (proto != kProtoSPDY1 && proto != kProtoSPDY21) + next_protos.push_back(proto); } return next_protos; } @@ -719,30 +720,6 @@ SpdyMajorVersion SpdyVersionFromNextProto(NextProto next_proto) { } } -AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { - switch (next_proto) { - case kProtoSPDY2: - return NPN_SPDY_2; - case kProtoSPDY3: - return NPN_SPDY_3; - case kProtoSPDY31: - return NPN_SPDY_3_1; - case kProtoSPDY4a2: - return NPN_SPDY_4A2; - case kProtoQUIC1SPDY3: - return QUIC; - - case kProtoUnknown: - case kProtoHTTP11: - case kProtoSPDY1: - case kProtoSPDY21: - break; - } - - NOTREACHED(); - return NPN_SPDY_2; -} - SpdyTestUtil::SpdyTestUtil(NextProto protocol) : protocol_(protocol), spdy_version_(SpdyVersionFromNextProto(protocol)) { diff --git a/net/spdy/spdy_test_util_common.h b/net/spdy/spdy_test_util_common.h index 92efc49..88fd678 100644 --- a/net/spdy/spdy_test_util_common.h +++ b/net/spdy/spdy_test_util_common.h @@ -48,9 +48,9 @@ const char kDefaultURL[] = "http://www.google.com"; const char kUploadData[] = "hello!"; const int kUploadDataSize = arraysize(kUploadData)-1; -// SpdyNextProtos returns a vector of NPN protocol strings for negotiating +// SpdyNextProtos returns a vector of next protocols for negotiating // SPDY. -std::vector<std::string> SpdyNextProtos(); +std::vector<NextProto> SpdyNextProtos(); // Chop a frame into an array of MockWrites. // |data| is the frame to chop. @@ -295,8 +295,6 @@ NextProto NextProtoFromSpdyVersion(SpdyMajorVersion spdy_version); // spdy_session.cc. SpdyMajorVersion SpdyVersionFromNextProto(NextProto next_proto); -AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto); - class SpdyTestUtil { public: explicit SpdyTestUtil(NextProto protocol); |