diff options
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 3 | ||||
-rw-r--r-- | net/http/http_stream_request.cc | 5 | ||||
-rw-r--r-- | net/proxy/proxy_server.cc | 24 | ||||
-rw-r--r-- | net/proxy/proxy_server.h | 7 | ||||
-rw-r--r-- | net/proxy/proxy_server_unittest.cc | 66 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 6 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 9 | ||||
-rw-r--r-- | net/spdy/spdy_session_pool.h | 7 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 2 |
10 files changed, 109 insertions, 22 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 56b73c5..5e07b88 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -5801,7 +5801,8 @@ TEST_F(HttpNetworkTransactionTest, EXPECT_EQ("hello world", response_data); // Set up an initial SpdySession in the pool to reuse. - HostPortProxyPair pair(HostPortPair("www.google.com", 443), "DIRECT"); + HostPortProxyPair pair(HostPortPair("www.google.com", 443), + ProxyServer::Direct()); scoped_refptr<SpdySession> spdy_session = session->spdy_session_pool()->Get(pair, session, BoundNetLog()); scoped_refptr<TCPSocketParams> tcp_params = diff --git a/net/http/http_stream_request.cc b/net/http/http_stream_request.cc index 3e9b157..8ca375b 100644 --- a/net/http/http_stream_request.cc +++ b/net/http/http_stream_request.cc @@ -423,7 +423,7 @@ int HttpStreamRequest::DoInitConnection() { // Check first if we have a spdy session for this group. If so, then go // straight to using that. - HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server().ToPacString()); + HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server()); if (session_->spdy_session_pool()->HasSession(pair)) { using_spdy_ = true; next_state_ = STATE_INIT_STREAM; @@ -684,8 +684,7 @@ int HttpStreamRequest::DoInitStream() { session_->spdy_session_pool(); scoped_refptr<SpdySession> spdy_session; - HostPortProxyPair pair(endpoint_, - proxy_info()->proxy_server().ToPacString()); + HostPortProxyPair pair(endpoint_, proxy_info()->proxy_server()); if (session_->spdy_session_pool()->HasSession(pair)) { spdy_session = session_->spdy_session_pool()->Get(pair, session_, net_log_); diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc index f172a6b..1cb6e68 100644 --- a/net/proxy/proxy_server.cc +++ b/net/proxy/proxy_server.cc @@ -72,6 +72,13 @@ std::string HostNoBrackets(const std::string& host) { ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) : scheme_(scheme), host_port_pair_(host_port_pair) { + if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) { + // |host_port_pair| isn't relevant for these special schemes, so none should + // have been specified. It is important for this to be consistent since we + // do raw field comparisons in the equality and comparison functions. + DCHECK(host_port_pair.Equals(HostPortPair())); + host_port_pair_ = HostPortPair(); + } } const HostPortPair& ProxyServer::host_port_pair() const { @@ -208,21 +215,24 @@ ProxyServer ProxyServer::FromSchemeHostAndPort( if (scheme == SCHEME_DIRECT && begin != end) return ProxyServer(); // Invalid -- DIRECT cannot have a host/port. - std::string host; - int port = -1; + HostPortPair host_port_pair; if (scheme != SCHEME_INVALID && scheme != SCHEME_DIRECT) { + std::string host; + int port = -1; // If the scheme has a host/port, parse it. bool ok = net::ParseHostAndPort(begin, end, &host, &port); if (!ok) return ProxyServer(); // Invalid -- failed parsing <host>[":"<port>] - } - // Choose a default port number if none was given. - if (port == -1) - port = GetDefaultPortForScheme(scheme); + // Choose a default port number if none was given. + if (port == -1) + port = GetDefaultPortForScheme(scheme); + + host_port_pair = HostPortPair(HostNoBrackets(host), port); + } - return ProxyServer(scheme, HostPortPair(HostNoBrackets(host), port)); + return ProxyServer(scheme, host_port_pair); } } // namespace net diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h index 689fd6b..dea910e 100644 --- a/net/proxy/proxy_server.h +++ b/net/proxy/proxy_server.h @@ -132,6 +132,13 @@ class ProxyServer { host_port_pair_.Equals(other.host_port_pair_); } + // Comparator function so this can be placed in a std::map. + bool operator<(const ProxyServer& other) const { + if (scheme_ != other.scheme_) + return scheme_ < other.scheme_; + return host_port_pair_ < other.host_port_pair_; + } + private: // Creates a ProxyServer given a scheme, and host/port string. If parsing the // host/port string fails, the returned instance will be invalid. diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc index 04f0770..2d470b1 100644 --- a/net/proxy/proxy_server_unittest.cc +++ b/net/proxy/proxy_server_unittest.cc @@ -300,3 +300,69 @@ TEST(ProxyServerTest, FromPACStringInvalid) { EXPECT_FALSE(uri.is_valid()); } } + +TEST(ProxyServerTest, ComparatorAndEquality) { + struct { + // Inputs. + const char* server1; + const char* server2; + + // Expectation. + // -1 means server1 is less than server2 + // 0 means server1 equals server2 + // 1 means server1 is greater than server2 + int expected_comparison; + } tests[] = { + { // Equal. + "foo:11", + "http://foo:11", + 0 + }, + { // Port is different. + "foo:333", + "foo:444", + -1 + }, + { // Host is different. + "foo:33", + "bar:33", + 1 + }, + { // Scheme is different. + "socks4://foo:33", + "http://foo:33", + 1 + }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { + // Parse the expected inputs to ProxyServer instances. + const net::ProxyServer server1 = + net::ProxyServer::FromURI( + tests[i].server1, net::ProxyServer::SCHEME_HTTP); + + const net::ProxyServer server2 = + net::ProxyServer::FromURI( + tests[i].server2, net::ProxyServer::SCHEME_HTTP); + + switch (tests[i].expected_comparison) { + case -1: + EXPECT_TRUE(server1 < server2); + EXPECT_FALSE(server2 < server1); + EXPECT_FALSE(server2 == server1); + break; + case 0: + EXPECT_FALSE(server1 < server2); + EXPECT_FALSE(server2 < server1); + EXPECT_TRUE(server2 == server1); + break; + case 1: + EXPECT_FALSE(server1 < server2); + EXPECT_TRUE(server2 < server1); + EXPECT_FALSE(server2 == server1); + break; + default: + FAIL() << "Invalid expectation. Can be only -1, 0, 1"; + } + } +} diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index 5af7d52..22244c4 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -25,7 +25,7 @@ class SpdyHttpStreamTest : public testing::Test { int InitSession(MockRead* reads, size_t reads_count, MockWrite* writes, size_t writes_count, HostPortPair& host_port_pair) { - HostPortProxyPair pair(host_port_pair, ""); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); data_ = new OrderedSocketData(reads, reads_count, writes, writes_count); session_deps_.socket_factory->AddSocketDataProvider(data_.get()); http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); @@ -58,7 +58,7 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ""); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); @@ -108,7 +108,7 @@ TEST_F(SpdyHttpStreamTest, SpdyURLTest) { }; HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ""); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes), host_port_pair)); diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 61630c3..f194eff 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -361,7 +361,7 @@ class SpdyNetworkTransactionTest const GURL& url = helper.request().url; int port = helper.test_type() == SPDYNPN ? 443 : 80; HostPortPair host_port_pair(url.host(), port); - HostPortProxyPair pair(host_port_pair, "DIRECT"); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); BoundNetLog log; const scoped_refptr<HttpNetworkSession>& session = helper.session(); scoped_refptr<SpdySessionPool> pool(session->spdy_session_pool()); @@ -4010,9 +4010,12 @@ TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { // Check that the SpdySession is still in the SpdySessionPool. HostPortPair host_port_pair("www.google.com", helper.port()); - HostPortProxyPair session_pool_key_direct(host_port_pair, "DIRECT"); + HostPortProxyPair session_pool_key_direct( + host_port_pair, ProxyServer::Direct()); EXPECT_TRUE(spdy_session_pool->HasSession(session_pool_key_direct)); - HostPortProxyPair session_pool_key_proxy(host_port_pair, "PROXY www.foo.com"); + HostPortProxyPair session_pool_key_proxy( + host_port_pair, + ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP)); EXPECT_FALSE(spdy_session_pool->HasSession(session_pool_key_proxy)); // Set up data for the proxy connection. diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h index 7efb400..149deb0 100644 --- a/net/spdy/spdy_session_pool.h +++ b/net/spdy/spdy_session_pool.h @@ -18,11 +18,12 @@ #include "net/base/net_errors.h" #include "net/base/network_change_notifier.h" #include "net/proxy/proxy_config.h" +#include "net/proxy/proxy_server.h" namespace net { -// Sessions are uniquely identified by their HostPortPair and the PAC-style list -// of valid proxy servers. -typedef std::pair<HostPortPair, std::string> HostPortProxyPair; +// Sessions are uniquely identified by their HostPortPair and the proxy server +// that will be used to connect to it (may be DIRECT). +typedef std::pair<HostPortPair, ProxyServer> HostPortProxyPair; class BoundNetLog; class ClientSocketHandle; diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index 83bb624..f53d022 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -80,7 +80,7 @@ TEST_F(SpdySessionTest, GoAway) { const std::string kTestHost("www.foo.com"); const int kTestPort = 80; HostPortPair test_host_port_pair(kTestHost, kTestPort); - HostPortProxyPair pair(test_host_port_pair, ""); + HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); scoped_refptr<SpdySessionPool> spdy_session_pool( http_session->spdy_session_pool()); diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 71664ad..57afd53 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -119,7 +119,7 @@ class SpdyStreamTest : public testing::Test { scoped_refptr<SpdySession> CreateSpdySession() { spdy::SpdyFramer::set_enable_compression_default(false); HostPortPair host_port_pair("www.google.com", 80); - HostPortProxyPair pair(host_port_pair, ""); + HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); scoped_refptr<SpdySession> session( session_->spdy_session_pool()->Get(pair, session_, BoundNetLog())); return session; |