summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/http/http_network_transaction_unittest.cc67
-rw-r--r--net/spdy/spdy_session_pool.cc6
-rw-r--r--net/spdy/spdy_session_pool.h2
3 files changed, 39 insertions, 36 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 2e76b4b..2a942dc 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -8704,35 +8704,32 @@ TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
}
}
-void IPPoolingPreloadHostCache(MockCachingHostResolver* host_resolver,
- SpdySessionPoolPeer* pool_peer) {
- const int kTestPort = 443;
- struct TestHosts {
- std::string name;
- std::string iplist;
- } test_hosts[] = {
- { "www.google.com", "127.0.0.1"},
- };
-
- // Preload cache entries into HostCache.
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
- host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name,
- test_hosts[i].iplist, "");
-
- AddressList addresses;
- // This test requires that the HostResolver cache be populated. Normal
- // code would have done this already, but we do it manually.
- HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
- host_resolver->Resolve(
- info, &addresses, NULL, NULL, BoundNetLog());
-
- // Setup a HostPortProxyPair
- HostPortProxyPair pair = HostPortProxyPair(
- HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
-
- const addrinfo* address = addresses.head();
- pool_peer->AddAlias(address, pair);
- }
+void IPPoolingAddAlias(MockCachingHostResolver* host_resolver,
+ SpdySessionPoolPeer* pool_peer,
+ std::string host,
+ int port,
+ std::string iplist) {
+ // Create a host resolver dependency that returns address |iplist| for
+ // resolutions of |host|.
+ host_resolver->rules()->AddIPLiteralRule(host, iplist, "");
+
+ // Setup a HostPortProxyPair.
+ HostPortPair host_port_pair(host, port);
+ HostPortProxyPair pair = HostPortProxyPair(host_port_pair,
+ ProxyServer::Direct());
+
+ // Resolve the host and port.
+ AddressList addresses;
+ HostResolver::RequestInfo info(host_port_pair);
+ host_resolver->Resolve(info, &addresses, NULL, NULL, BoundNetLog());
+
+ // Add the first address as an alias. It would have been better to call
+ // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas
+ // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use
+ // the first address (127.0.0.1) returned by MockHostResolver as an alias for
+ // the |pair|.
+ const addrinfo* address = addresses.head();
+ pool_peer->AddAlias(address, pair);
}
TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
@@ -8813,7 +8810,11 @@ TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
AddressList ignored;
host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
- IPPoolingPreloadHostCache(&host_resolver, &pool_peer);
+ // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
+ // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
+ // (www.google.com, 443).
+ IPPoolingAddAlias(&host_resolver, &pool_peer, "www.google.com", 443,
+ "127.0.0.1");
HttpRequestInfo request2;
request2.method = "GET";
@@ -8967,7 +8968,11 @@ TEST_F(HttpNetworkTransactionTest,
request2.load_flags = 0;
HttpNetworkTransaction trans2(session);
- IPPoolingPreloadHostCache(host_resolver.GetMockHostResolver(), &pool_peer);
+ // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
+ // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
+ // (www.google.com, 443).
+ IPPoolingAddAlias(host_resolver.GetMockHostResolver(), &pool_peer,
+ "www.google.com", 443, "127.0.0.1");
rv = trans2.Start(&request2, &callback, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc
index e8324f4..c0a5194 100644
--- a/net/spdy/spdy_session_pool.cc
+++ b/net/spdy/spdy_session_pool.cc
@@ -157,10 +157,8 @@ net::Error SpdySessionPool::GetSpdySessionFromSocket(
// direct connection.
if (g_enable_ip_pooling && host_port_proxy_pair.second.is_direct()) {
AddressList addresses;
- if (connection->socket()->GetPeerAddress(&addresses) == OK) {
- const addrinfo* address = addresses.head();
- AddAlias(address, host_port_proxy_pair);
- }
+ if (connection->socket()->GetPeerAddress(&addresses) == OK)
+ AddAlias(addresses.head(), host_port_proxy_pair);
}
// Now we can initialize the session with the SSL socket.
diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h
index 366ede4..ba02eed 100644
--- a/net/spdy/spdy_session_pool.h
+++ b/net/spdy/spdy_session_pool.h
@@ -163,7 +163,7 @@ class NET_API SpdySessionPool
bool LookupAddresses(const HostPortProxyPair& pair,
AddressList* addresses) const;
- // Add |endpoint| as an IP-equivalent address for |pair|.
+ // Add |address| as an IP-equivalent address for |pair|.
void AddAlias(const addrinfo* address, const HostPortProxyPair& pair);
// Remove all aliases for |pair| from the aliases table.