diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-22 20:56:47 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-22 20:56:47 +0000 |
commit | de6251d099e919502c13dddd01492ad1831d2c5f (patch) | |
tree | 73f2e4077755c9bf76363c7879595640175c1832 /net/http | |
parent | a88fe62cc7255cccd97dc4f13cb6f6f0b5b77fe2 (diff) | |
download | chromium_src-de6251d099e919502c13dddd01492ad1831d2c5f.zip chromium_src-de6251d099e919502c13dddd01492ad1831d2c5f.tar.gz chromium_src-de6251d099e919502c13dddd01492ad1831d2c5f.tar.bz2 |
Add option to simulate alternate protocol always being present.
It's a bit hardcoded (port 443, NPN/SPDY2), but it is just for
testing purposes.
To use this mode, run chrome with:
chrome.exe --use-spdy=npn,force-alt-protocols
BUG=none
TEST=http_alternate_protocols_unittest.cc
Review URL: http://codereview.chromium.org/3195015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_alternate_protocols.cc | 34 | ||||
-rw-r--r-- | net/http/http_alternate_protocols.h | 10 | ||||
-rw-r--r-- | net/http/http_alternate_protocols_unittest.cc | 37 | ||||
-rw-r--r-- | net/http/http_network_layer.cc | 6 |
4 files changed, 84 insertions, 3 deletions
diff --git a/net/http/http_alternate_protocols.cc b/net/http/http_alternate_protocols.cc index fbd1d92..e37af69 100644 --- a/net/http/http_alternate_protocols.cc +++ b/net/http/http_alternate_protocols.cc @@ -15,12 +15,17 @@ const char* const HttpAlternateProtocols::kProtocolStrings[] = { "npn-spdy/2", }; +// static +HttpAlternateProtocols::PortProtocolPair* + HttpAlternateProtocols::forced_alternate_protocol_ = NULL; + HttpAlternateProtocols::HttpAlternateProtocols() {} HttpAlternateProtocols::~HttpAlternateProtocols() {} bool HttpAlternateProtocols::HasAlternateProtocolFor( const HostPortPair& http_host_port_pair) const { - return ContainsKey(protocol_map_, http_host_port_pair); + return ContainsKey(protocol_map_, http_host_port_pair) || + forced_alternate_protocol_; } bool HttpAlternateProtocols::HasAlternateProtocolFor( @@ -32,8 +37,16 @@ bool HttpAlternateProtocols::HasAlternateProtocolFor( HttpAlternateProtocols::PortProtocolPair HttpAlternateProtocols::GetAlternateProtocolFor( const HostPortPair& http_host_port_pair) const { - DCHECK(ContainsKey(protocol_map_, http_host_port_pair)); - return protocol_map_.find(http_host_port_pair)->second; + DCHECK(HasAlternateProtocolFor(http_host_port_pair)); + + // First check the map. + ProtocolMap::const_iterator it = protocol_map_.find(http_host_port_pair); + if (it != protocol_map_.end()) + return it->second; + + // We must be forcing an alternate. + DCHECK(forced_alternate_protocol_); + return *forced_alternate_protocol_; } HttpAlternateProtocols::PortProtocolPair @@ -83,4 +96,19 @@ void HttpAlternateProtocols::MarkBrokenAlternateProtocolFor( protocol_map_[http_host_port_pair].protocol = BROKEN; } +// static +void HttpAlternateProtocols::ForceAlternateProtocol( + const PortProtocolPair& pair) { + // Note: we're going to leak this. + if (forced_alternate_protocol_) + delete forced_alternate_protocol_; + forced_alternate_protocol_ = new PortProtocolPair(pair); +} + +// static +void HttpAlternateProtocols::DisableForcedAlternateProtocol() { + delete forced_alternate_protocol_; + forced_alternate_protocol_ = NULL; +} + } // namespace net diff --git a/net/http/http_alternate_protocols.h b/net/http/http_alternate_protocols.h index 22bbac3..e06e13a 100644 --- a/net/http/http_alternate_protocols.h +++ b/net/http/http_alternate_protocols.h @@ -63,11 +63,21 @@ class HttpAlternateProtocols { // attempts to set the alternate protocol for |http_host_port_pair| will fail. void MarkBrokenAlternateProtocolFor(const HostPortPair& http_host_port_pair); + // Debugging to simulate presence of an AlternateProtocol. + // If we don't have an alternate protocol in the map for any given host/port + // pair, force this ProtocolPortPair. + static void ForceAlternateProtocol(const PortProtocolPair& pair); + static void DisableForcedAlternateProtocol(); + private: typedef std::map<HostPortPair, PortProtocolPair> ProtocolMap; ProtocolMap protocol_map_; + // The forced alternate protocol. If not-null, there is a protocol being + // forced. + static PortProtocolPair* forced_alternate_protocol_; + DISALLOW_COPY_AND_ASSIGN(HttpAlternateProtocols); }; diff --git a/net/http/http_alternate_protocols_unittest.cc b/net/http/http_alternate_protocols_unittest.cc index 0cf6f9a..8a2ac66 100644 --- a/net/http/http_alternate_protocols_unittest.cc +++ b/net/http/http_alternate_protocols_unittest.cc @@ -44,5 +44,42 @@ TEST(HttpAlternateProtocols, SetBroken) { << "Second attempt should be ignored."; } +TEST(HttpAlternateProtocols, Forced) { + // Test forced alternate protocols. + + HttpAlternateProtocols::PortProtocolPair default_protocol; + default_protocol.port = 1234; + default_protocol.protocol = HttpAlternateProtocols::NPN_SPDY_2; + HttpAlternateProtocols::ForceAlternateProtocol(default_protocol); + + HttpAlternateProtocols alternate_protocols; + + // Verify the forced protocol. + HostPortPair test_host_port_pair("foo", 80); + EXPECT_TRUE( + alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); + HttpAlternateProtocols::PortProtocolPair alternate = + alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); + EXPECT_EQ(default_protocol.port, alternate.port); + EXPECT_EQ(default_protocol.protocol, alternate.protocol); + + // Verify the real protocol overrides the forced protocol. + alternate_protocols.SetAlternateProtocolFor( + test_host_port_pair, 443, HttpAlternateProtocols::NPN_SPDY_1); + ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); + alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); + EXPECT_EQ(443, alternate.port); + EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); + + // Turn off the static, forced alternate protocol so that tests don't + // have this state. + HttpAlternateProtocols::DisableForcedAlternateProtocol(); + + // Verify the forced protocol is off. + HostPortPair test_host_port_pair2("bar", 80); + EXPECT_FALSE( + alternate_protocols.HasAlternateProtocolFor(test_host_port_pair2)); +} + } // namespace } // namespace net diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 24c410e..95f9ea9 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -148,6 +148,7 @@ void HttpNetworkLayer::EnableSpdy(const std::string& mode) { static const char kDisableCompression[] = "no-compress"; static const char kDisableAltProtocols[] = "no-alt-protocols"; static const char kEnableVersionOne[] = "v1"; + static const char kForceAltProtocols[] = "force-alt-protocols"; // If flow-control is enabled, received WINDOW_UPDATE and SETTINGS // messages are processed and outstanding window size is actually obeyed @@ -210,6 +211,11 @@ void HttpNetworkLayer::EnableSpdy(const std::string& mode) { HttpStreamFactory::set_use_alternate_protocols(false); } else if (option == kEnableFlowControl) { SpdySession::SetFlowControl(true); + } else if (option == kForceAltProtocols) { + HttpAlternateProtocols::PortProtocolPair pair; + pair.port = 443; + pair.protocol = HttpAlternateProtocols::NPN_SPDY_2; + HttpAlternateProtocols::ForceAlternateProtocol(pair); } else if (option.empty() && it == spdy_options.begin()) { continue; } else { |