summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-22 22:20:35 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-22 22:20:35 +0000
commit2fbaecf27edd63f4f760581b798a99dcdf78a5eb (patch)
treea974662967015c83e63ccd7944aac2d2dc784b8f /net
parenta063c102fd36f61f4a0a01447f4b01ace4ffccdf (diff)
downloadchromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.zip
chromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.tar.gz
chromium_src-2fbaecf27edd63f4f760581b798a99dcdf78a5eb.tar.bz2
Net: Get rid of ProxyServer::host_and_port() and friends.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3032017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/host_mapping_rules.cc8
-rw-r--r--net/base/host_mapping_rules.h4
-rw-r--r--net/base/host_mapping_rules_unittest.cc16
-rw-r--r--net/base/host_port_pair.cc12
-rw-r--r--net/base/host_port_pair.h41
-rw-r--r--net/base/mapped_host_resolver.cc4
-rw-r--r--net/http/http_alternate_protocols.cc8
-rw-r--r--net/http/http_alternate_protocols.h2
-rw-r--r--net/http/http_alternate_protocols_unittest.cc8
-rw-r--r--net/http/http_network_transaction.cc26
-rw-r--r--net/http/http_network_transaction_unittest.cc12
-rw-r--r--net/proxy/proxy_server.cc52
-rw-r--r--net/proxy/proxy_server.h30
-rw-r--r--net/proxy/proxy_server_unittest.cc24
-rw-r--r--net/socket/socks_client_socket_pool.cc2
-rw-r--r--net/socket/tcp_client_socket_pool.cc2
-rw-r--r--net/socket_stream/socket_stream.cc13
-rw-r--r--net/spdy/spdy_http_stream_unittest.cc6
-rw-r--r--net/spdy/spdy_session_unittest.cc8
19 files changed, 118 insertions, 160 deletions
diff --git a/net/base/host_mapping_rules.cc b/net/base/host_mapping_rules.cc
index 3296b0e..ab560a7 100644
--- a/net/base/host_mapping_rules.cc
+++ b/net/base/host_mapping_rules.cc
@@ -19,7 +19,7 @@ bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin();
it != exclusion_rules_.end(); ++it) {
const ExclusionRule& rule = *it;
- if (MatchPatternASCII(host_port->host, rule.hostname_pattern))
+ if (MatchPatternASCII(host_port->host(), rule.hostname_pattern))
return false;
}
@@ -28,12 +28,12 @@ bool HostMappingRules::RewriteHost(HostPortPair* host_port) const {
it != map_rules_.end(); ++it) {
const MapRule& rule = *it;
- if (!MatchPatternASCII(host_port->host, rule.hostname_pattern))
+ if (!MatchPatternASCII(host_port->host(), rule.hostname_pattern))
continue; // This rule doesn't apply.
- host_port->host = rule.replacement_hostname;
+ host_port->set_host(rule.replacement_hostname);
if (rule.replacement_port != -1)
- host_port->port = rule.replacement_port;
+ host_port->set_port(rule.replacement_port);
return true;
}
diff --git a/net/base/host_mapping_rules.h b/net/base/host_mapping_rules.h
index a754a47..e9b3484 100644
--- a/net/base/host_mapping_rules.h
+++ b/net/base/host_mapping_rules.h
@@ -11,12 +11,12 @@
namespace net {
-struct HostPortPair;
+class HostPortPair;
class HostMappingRules {
public:
HostMappingRules();
-
+
// Modifies |*host_port| based on the current rules. Returns true if the
// RequestInfo was modified, false otherwise.
bool RewriteHost(HostPortPair* host_port) const;
diff --git a/net/base/host_mapping_rules_unittest.cc b/net/base/host_mapping_rules_unittest.cc
index 0cea821..09e7f45 100644
--- a/net/base/host_mapping_rules_unittest.cc
+++ b/net/base/host_mapping_rules_unittest.cc
@@ -18,23 +18,23 @@ TEST(HostMappingRulesTest, SetRulesFromString) {
HostPortPair host_port("test", 1234);
EXPECT_FALSE(rules.RewriteHost(&host_port));
- EXPECT_EQ("test", host_port.host);
- EXPECT_EQ(1234u, host_port.port);
+ EXPECT_EQ("test", host_port.host());
+ EXPECT_EQ(1234u, host_port.port());
host_port = HostPortPair("chrome.net", 80);
EXPECT_TRUE(rules.RewriteHost(&host_port));
- EXPECT_EQ("bar", host_port.host);
- EXPECT_EQ(60u, host_port.port);
+ EXPECT_EQ("bar", host_port.host());
+ EXPECT_EQ(60u, host_port.port());
host_port = HostPortPair("crack.com", 80);
EXPECT_TRUE(rules.RewriteHost(&host_port));
- EXPECT_EQ("baz", host_port.host);
- EXPECT_EQ(80u, host_port.port);
+ EXPECT_EQ("baz", host_port.host());
+ EXPECT_EQ(80u, host_port.port());
host_port = HostPortPair("wtf.foo.com", 666);
EXPECT_FALSE(rules.RewriteHost(&host_port));
- EXPECT_EQ("wtf.foo.com", host_port.host);
- EXPECT_EQ(666u, host_port.port);
+ EXPECT_EQ("wtf.foo.com", host_port.host());
+ EXPECT_EQ(666u, host_port.port());
}
// Parsing bad rules should silently discard the rule (and never crash).
diff --git a/net/base/host_port_pair.cc b/net/base/host_port_pair.cc
index d4e7d4e..645d958 100644
--- a/net/base/host_port_pair.cc
+++ b/net/base/host_port_pair.cc
@@ -7,15 +7,17 @@
namespace net {
-HostPortPair::HostPortPair() : port(0) {}
+HostPortPair::HostPortPair() : port_(0) {}
HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port)
- : host(in_host), port(in_port) {}
+ : host_(in_host), port_(in_port) {}
std::string HostPortPair::ToString() const {
// Check to see if the host is an IPv6 address. If so, added brackets.
- if (host.find(':') != std::string::npos)
- return StringPrintf("[%s]:%u", host.c_str(), port);
- return StringPrintf("%s:%u", host.c_str(), port);
+ if (host_.find(':') != std::string::npos) {
+ DCHECK_NE(host_[0], '[');
+ return StringPrintf("[%s]:%u", host_.c_str(), port_);
+ }
+ return StringPrintf("%s:%u", host_.c_str(), port_);
}
} // namespace net
diff --git a/net/base/host_port_pair.h b/net/base/host_port_pair.h
index 78f74ea..7c1d33f 100644
--- a/net/base/host_port_pair.h
+++ b/net/base/host_port_pair.h
@@ -10,33 +10,50 @@
namespace net {
-struct HostPortPair {
+class HostPortPair {
+ public:
HostPortPair();
// If |in_host| represents an IPv6 address, it should not bracket the address.
HostPortPair(const std::string& in_host, uint16 in_port);
// TODO(willchan): Define a functor instead.
// Comparator function so this can be placed in a std::map.
- // TODO(jar): Violation of style guide, and should be removed.
bool operator<(const HostPortPair& other) const {
- if (port != other.port)
- return port < other.port;
- return host < other.host;
+ if (port_ != other.port_)
+ return port_ < other.port_;
+ return host_ < other.host_;
}
// Equality test of contents. (Probably another violation of style guide).
bool Equals(const HostPortPair& other) const {
- return host == other.host && port == other.port;
+ return host_ == other.host_ && port_ == other.port_;
}
- // ToString() will convert the HostPortPair to "host:port". If |host| is an
- // IPv6 literal, it will add brackets around |host|.
+ const std::string& host() const {
+ return host_;
+ }
+
+ uint16 port() const {
+ return port_;
+ }
+
+ void set_host(const std::string& in_host) {
+ host_ = in_host;
+ }
+
+ void set_port(uint16 in_port) {
+ port_ = in_port;
+ }
+
+ // ToString() will convert the HostPortPair to "host:port". If |host_| is an
+ // IPv6 literal, it will add brackets around |host_|.
std::string ToString() const;
- // If |host| represents an IPv6 address, this string will not contain brackets
- // around the address.
- std::string host;
- uint16 port;
+ private:
+ // If |host_| represents an IPv6 address, this string will not contain
+ // brackets around the address.
+ std::string host_;
+ uint16 port_;
};
} // namespace net
diff --git a/net/base/mapped_host_resolver.cc b/net/base/mapped_host_resolver.cc
index b401917..0349232 100644
--- a/net/base/mapped_host_resolver.cc
+++ b/net/base/mapped_host_resolver.cc
@@ -24,8 +24,8 @@ int MappedHostResolver::Resolve(const RequestInfo& info,
RequestInfo modified_info = info;
HostPortPair host_port(info.hostname(), info.port());
if (rules_.RewriteHost(&host_port)) {
- modified_info.set_hostname(host_port.host);
- modified_info.set_port(host_port.port);
+ modified_info.set_hostname(host_port.host());
+ modified_info.set_port(host_port.port());
}
return impl_->Resolve(modified_info, addresses, callback, out_req, net_log);
}
diff --git a/net/http/http_alternate_protocols.cc b/net/http/http_alternate_protocols.cc
index cd42ed5..c3804ac4 100644
--- a/net/http/http_alternate_protocols.cc
+++ b/net/http/http_alternate_protocols.cc
@@ -24,9 +24,7 @@ bool HttpAlternateProtocols::HasAlternateProtocolFor(
bool HttpAlternateProtocols::HasAlternateProtocolFor(
const std::string& host, uint16 port) const {
- struct HostPortPair http_host_port_pair;
- http_host_port_pair.host = host;
- http_host_port_pair.port = port;
+ HostPortPair http_host_port_pair(host, port);
return HasAlternateProtocolFor(http_host_port_pair);
}
@@ -40,9 +38,7 @@ HttpAlternateProtocols::GetAlternateProtocolFor(
HttpAlternateProtocols::PortProtocolPair
HttpAlternateProtocols::GetAlternateProtocolFor(
const std::string& host, uint16 port) const {
- struct HostPortPair http_host_port_pair;
- http_host_port_pair.host = host;
- http_host_port_pair.port = port;
+ HostPortPair http_host_port_pair(host, port);
return GetAlternateProtocolFor(http_host_port_pair);
}
diff --git a/net/http/http_alternate_protocols.h b/net/http/http_alternate_protocols.h
index 56fb49a..0c16798 100644
--- a/net/http/http_alternate_protocols.h
+++ b/net/http/http_alternate_protocols.h
@@ -10,7 +10,9 @@
#define NET_HTTP_HTTP_ALTERNATE_PROTOCOLS_H_
#include <map>
+#include <string>
#include <utility>
+
#include "base/basictypes.h"
#include "net/base/host_port_pair.h"
diff --git a/net/http/http_alternate_protocols_unittest.cc b/net/http/http_alternate_protocols_unittest.cc
index d82f850..0cf6f9a 100644
--- a/net/http/http_alternate_protocols_unittest.cc
+++ b/net/http/http_alternate_protocols_unittest.cc
@@ -14,9 +14,7 @@ namespace {
TEST(HttpAlternateProtocols, Basic) {
HttpAlternateProtocols alternate_protocols;
- HostPortPair test_host_port_pair;
- test_host_port_pair.host = "foo";
- test_host_port_pair.port = 80;
+ HostPortPair test_host_port_pair("foo", 80);
EXPECT_FALSE(
alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
alternate_protocols.SetAlternateProtocolFor(
@@ -30,9 +28,7 @@ TEST(HttpAlternateProtocols, Basic) {
TEST(HttpAlternateProtocols, SetBroken) {
HttpAlternateProtocols alternate_protocols;
- HostPortPair test_host_port_pair;
- test_host_port_pair.host = "foo";
- test_host_port_pair.port = 80;
+ HostPortPair test_host_port_pair("foo", 80);
alternate_protocols.MarkBrokenAlternateProtocolFor(test_host_port_pair);
ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
HttpAlternateProtocols::PortProtocolPair alternate =
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index a85a1ca..2e5b437 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -4,6 +4,9 @@
#include "net/http/http_network_transaction.h"
+#include <set>
+#include <vector>
+
#include "base/compiler_specific.h"
#include "base/field_trial.h"
#include "base/format_macros.h"
@@ -133,7 +136,6 @@ void BuildRequestHeaders(const HttpRequestInfo* request_info,
void ProcessAlternateProtocol(const HttpResponseHeaders& headers,
const HostPortPair& http_host_port_pair,
HttpAlternateProtocols* alternate_protocols) {
-
std::string alternate_protocol_str;
if (!headers.EnumerateHeader(NULL, HttpAlternateProtocols::kHeader,
&alternate_protocol_str)) {
@@ -630,11 +632,11 @@ int HttpNetworkTransaction::DoResolveProxy() {
if (g_host_mapping_rules && g_host_mapping_rules->RewriteHost(&endpoint_)) {
url_canon::Replacements<char> replacements;
- const std::string port_str = IntToString(endpoint_.port);
+ const std::string port_str = IntToString(endpoint_.port());
replacements.SetPort(port_str.c_str(),
url_parse::Component(0, port_str.size()));
- replacements.SetHost(endpoint_.host.c_str(),
- url_parse::Component(0, endpoint_.host.size()));
+ replacements.SetHost(endpoint_.host().c_str(),
+ url_parse::Component(0, endpoint_.host().size()));
alternate_endpoint_url = curr_endpoint_url->ReplaceComponents(replacements);
curr_endpoint_url = &alternate_endpoint_url;
}
@@ -648,14 +650,14 @@ int HttpNetworkTransaction::DoResolveProxy() {
alternate_protocols.GetAlternateProtocolFor(endpoint_);
if (alternate.protocol != HttpAlternateProtocols::BROKEN) {
DCHECK_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol);
- endpoint_.port = alternate.port;
+ endpoint_.set_port(alternate.port);
alternate_protocol_ = HttpAlternateProtocols::NPN_SPDY_1;
alternate_protocol_mode_ = kUsingAlternateProtocol;
url_canon::Replacements<char> replacements;
replacements.SetScheme("https",
url_parse::Component(0, strlen("https")));
- const std::string port_str = IntToString(endpoint_.port);
+ const std::string port_str = IntToString(endpoint_.port());
replacements.SetPort(port_str.c_str(),
url_parse::Component(0, port_str.size()));
alternate_endpoint_url =
@@ -718,9 +720,9 @@ int HttpNetworkTransaction::DoInitConnection() {
// Use the fixed testing ports if they've been provided.
if (using_ssl_) {
if (session_->fixed_https_port() != 0)
- endpoint_.port = session_->fixed_https_port();
+ endpoint_.set_port(session_->fixed_https_port());
} else if (session_->fixed_http_port() != 0) {
- endpoint_.port = session_->fixed_http_port();
+ endpoint_.set_port(session_->fixed_http_port());
}
// Check first if we have a spdy session for this group. If so, then go
@@ -757,8 +759,7 @@ int HttpNetworkTransaction::DoInitConnection() {
disable_resolver_cache);
} else {
ProxyServer proxy_server = proxy_info_.proxy_server();
- proxy_host_port.reset(new HostPortPair(proxy_server.HostNoBrackets(),
- proxy_server.port()));
+ proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair()));
scoped_refptr<TCPSocketParams> proxy_tcp_params =
new TCPSocketParams(*proxy_host_port, request_->priority,
request_->referrer, disable_resolver_cache);
@@ -1254,7 +1255,7 @@ int HttpNetworkTransaction::DoSpdyGetStream() {
}
CHECK(spdy_session.get());
- if(spdy_session->IsClosed())
+ if (spdy_session->IsClosed())
return ERR_CONNECTION_CLOSED;
headers_valid_ = false;
@@ -1722,7 +1723,8 @@ GURL HttpNetworkTransaction::AuthURL(HttpAuth::Target target) const {
proxy_info_.proxy_server().is_direct()) {
return GURL(); // There is no proxy server.
}
- return GURL("http://" + proxy_info_.proxy_server().host_and_port());
+ return GURL("http://" +
+ proxy_info_.proxy_server().host_port_pair().ToString());
case HttpAuth::AUTH_SERVER:
return request_->url;
default:
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 03e4b31..11c3965 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -4983,9 +4983,7 @@ TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) {
int rv = trans->Start(&request, &callback, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- HostPortPair http_host_port_pair;
- http_host_port_pair.host = "www.google.com";
- http_host_port_pair.port = 80;
+ HostPortPair http_host_port_pair("www.google.com", 80);
const HttpAlternateProtocols& alternate_protocols =
session->alternate_protocols();
EXPECT_FALSE(
@@ -5049,9 +5047,7 @@ TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocol) {
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
- HostPortPair http_host_port_pair;
- http_host_port_pair.host = "www.google.com";
- http_host_port_pair.port = 80;
+ HostPortPair http_host_port_pair("www.google.com", 80);
HttpAlternateProtocols* alternate_protocols =
session->mutable_alternate_protocols();
alternate_protocols->SetAlternateProtocolFor(
@@ -5164,9 +5160,7 @@ TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) {
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
- HostPortPair http_host_port_pair;
- http_host_port_pair.host = "www.google.com";
- http_host_port_pair.port = 80;
+ HostPortPair http_host_port_pair("www.google.com", 80);
HttpAlternateProtocols* alternate_protocols =
session->mutable_alternate_protocols();
alternate_protocols->SetAlternateProtocolFor(
diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc
index b78c347..792a47d 100644
--- a/net/proxy/proxy_server.cc
+++ b/net/proxy/proxy_server.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -60,39 +60,25 @@ ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin,
return ProxyServer::SCHEME_INVALID;
}
-} // namespace
-
-std::string ProxyServer::HostNoBrackets() const {
- // Doesn't make sense to call this if the URI scheme doesn't
- // have concept of a host.
- DCHECK(is_valid() && !is_direct());
-
+std::string HostNoBrackets(const std::string& host) {
// Remove brackets from an RFC 2732-style IPv6 literal address.
- const std::string::size_type len = host_.size();
- if (len != 0 && host_[0] == '[' && host_[len - 1] == ']')
- return host_.substr(1, len - 2);
- return host_;
+ const std::string::size_type len = host.size();
+ if (len >= 2 && host[0] == '[' && host[len - 1] == ']')
+ return host.substr(1, len - 2);
+ return host;
}
-int ProxyServer::port() const {
- // Doesn't make sense to call this if the URI scheme doesn't
- // have concept of a port.
- DCHECK(is_valid() && !is_direct());
- return port_;
-}
+} // namespace
-std::string ProxyServer::host_and_port() const {
- // Doesn't make sense to call this if the URI scheme doesn't
- // have concept of a host.
- DCHECK(is_valid() && !is_direct());
- return host_ + ":" + IntToString(port_);
+ProxyServer::ProxyServer(Scheme scheme, const std::string& host, int port)
+ : scheme_(scheme), host_port_pair_(HostNoBrackets(host), port) {
}
-HostPortPair ProxyServer::host_port_pair() const {
+const HostPortPair& ProxyServer::host_port_pair() const {
// Doesn't make sense to call this if the URI scheme doesn't
// have concept of a host.
DCHECK(is_valid() && !is_direct());
- return HostPortPair(host_, port_);
+ return host_port_pair_;
}
// static
@@ -131,13 +117,13 @@ std::string ProxyServer::ToURI() const {
return "direct://";
case SCHEME_HTTP:
// Leave off "http://" since it is our default scheme.
- return host_and_port();
+ return host_port_pair().ToString();
case SCHEME_SOCKS4:
- return std::string("socks4://") + host_and_port();
+ return std::string("socks4://") + host_port_pair().ToString();
case SCHEME_SOCKS5:
- return std::string("socks5://") + host_and_port();
+ return std::string("socks5://") + host_port_pair().ToString();
case SCHEME_HTTPS:
- return std::string("https://") + host_and_port();
+ return std::string("https://") + host_port_pair().ToString();
default:
// Got called with an invalid scheme.
NOTREACHED();
@@ -180,14 +166,14 @@ std::string ProxyServer::ToPacString() const {
case SCHEME_DIRECT:
return "DIRECT";
case SCHEME_HTTP:
- return std::string("PROXY ") + host_and_port();
+ return std::string("PROXY ") + host_port_pair().ToString();
case SCHEME_SOCKS4:
// For compatibility send SOCKS instead of SOCKS4.
- return std::string("SOCKS ") + host_and_port();
+ return std::string("SOCKS ") + host_port_pair().ToString();
case SCHEME_SOCKS5:
- return std::string("SOCKS5 ") + host_and_port();
+ return std::string("SOCKS5 ") + host_port_pair().ToString();
case SCHEME_HTTPS:
- return std::string("HTTPS ") + host_and_port();
+ return std::string("HTTPS ") + host_port_pair().ToString();
default:
// Got called with an invalid scheme.
NOTREACHED();
diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h
index 3d5593c..ea06188 100644
--- a/net/proxy/proxy_server.h
+++ b/net/proxy/proxy_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,12 +35,12 @@ class ProxyServer {
// Default copy-constructor and assignment operator are OK!
// Constructs an invalid ProxyServer.
- ProxyServer() : scheme_(SCHEME_INVALID), port_(-1) {}
+ ProxyServer() : scheme_(SCHEME_INVALID) {}
+ // TODO(thestig) Replace |host| and |port| with HostPortPair.
// If |host| is an IPv6 literal address, it must include the square
// brackets.
- ProxyServer(Scheme scheme, const std::string& host, int port)
- : scheme_(scheme), host_(host), port_(port) {}
+ ProxyServer(Scheme scheme, const std::string& host, int port);
bool is_valid() const { return scheme_ != SCHEME_INVALID; }
@@ -61,21 +61,7 @@ class ProxyServer {
return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5;
}
- // Gets the host portion of the proxy server. If the host portion is an
- // IPv6 literal address, the return value does not include the square
- // brackets ([]) used to separate it from the port portion.
- std::string HostNoBrackets() const;
-
- // Gets the port portion of the proxy server.
- int port() const;
-
- // Returns the <host>":"<port> string for the proxy server.
- // TODO(willchan): Remove in favor of host_port_pair().
- std::string host_and_port() const;
-
- // TODO(willchan): Change to const HostPortPair& after refactoring |host_| and
- // |port_| here.
- HostPortPair host_port_pair() const;
+ const HostPortPair& host_port_pair() const;
// Parses from an input with format:
// [<scheme>"://"]<server>[":"<port>]
@@ -145,8 +131,7 @@ class ProxyServer {
bool operator==(const ProxyServer& other) const {
return scheme_ == other.scheme_ &&
- host_ == other.host_ &&
- port_ == other.port_;
+ host_port_pair_.Equals(other.host_port_pair_);
}
private:
@@ -158,8 +143,7 @@ class ProxyServer {
std::string::const_iterator host_and_port_end);
Scheme scheme_;
- std::string host_;
- int port_;
+ HostPortPair host_port_pair_;
};
} // namespace net
diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc
index f91ad66..04f0770 100644
--- a/net/proxy/proxy_server_unittest.cc
+++ b/net/proxy/proxy_server_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,7 +16,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::Scheme expected_scheme;
const char* expected_host;
int expected_port;
- const char* expected_host_and_port;
const char* expected_pac_string;
} tests[] = {
// HTTP proxy URIs:
@@ -26,7 +25,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"foopy",
10,
- "foopy:10",
"PROXY foopy:10"
},
{
@@ -35,7 +33,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"foopy",
80,
- "foopy:80",
"PROXY foopy:80"
},
{
@@ -44,7 +41,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"foopy",
10,
- "foopy:10",
"PROXY foopy:10"
},
@@ -55,7 +51,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
10,
- "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10",
"PROXY [FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10"
},
{
@@ -64,7 +59,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"3ffe:2a00:100:7031::1",
80,
- "[3ffe:2a00:100:7031::1]:80",
"PROXY [3ffe:2a00:100:7031::1]:80"
},
{
@@ -73,7 +67,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"::192.9.5.5",
80,
- "[::192.9.5.5]:80",
"PROXY [::192.9.5.5]:80"
},
{
@@ -82,7 +75,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTP,
"::FFFF:129.144.52.38",
80,
- "[::FFFF:129.144.52.38]:80",
"PROXY [::FFFF:129.144.52.38]:80"
},
@@ -93,7 +85,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS4,
"foopy",
1080,
- "foopy:1080",
"SOCKS foopy:1080"
},
{
@@ -102,7 +93,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS4,
"foopy",
10,
- "foopy:10",
"SOCKS foopy:10"
},
@@ -113,7 +103,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS5,
"foopy",
1080,
- "foopy:1080",
"SOCKS5 foopy:1080"
},
{
@@ -122,7 +111,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS5,
"foopy",
10,
- "foopy:10",
"SOCKS5 foopy:10"
},
@@ -133,7 +121,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS4,
"foopy",
1080,
- "foopy:1080",
"SOCKS foopy:1080"
},
{
@@ -142,7 +129,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_SOCKS4,
"foopy",
10,
- "foopy:10",
"SOCKS foopy:10"
},
@@ -153,7 +139,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTPS,
"foopy",
443,
- "foopy:443",
"HTTPS foopy:443"
},
{
@@ -162,7 +147,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTPS,
"foopy",
10,
- "foopy:10",
"HTTPS foopy:10"
},
{
@@ -171,7 +155,6 @@ TEST(ProxyServerTest, FromURI) {
net::ProxyServer::SCHEME_HTTPS,
"1.2.3.4",
10,
- "1.2.3.4:10",
"HTTPS 1.2.3.4:10"
},
};
@@ -184,9 +167,8 @@ TEST(ProxyServerTest, FromURI) {
EXPECT_FALSE(uri.is_direct());
EXPECT_EQ(tests[i].expected_uri, uri.ToURI());
EXPECT_EQ(tests[i].expected_scheme, uri.scheme());
- EXPECT_EQ(tests[i].expected_host, uri.HostNoBrackets());
- EXPECT_EQ(tests[i].expected_port, uri.port());
- EXPECT_EQ(tests[i].expected_host_and_port, uri.host_and_port());
+ EXPECT_EQ(tests[i].expected_host, uri.host_port_pair().host());
+ EXPECT_EQ(tests[i].expected_port, uri.host_port_pair().port());
EXPECT_EQ(tests[i].expected_pac_string, uri.ToPacString());
}
}
diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc
index d1c75b6..1241338 100644
--- a/net/socket/socks_client_socket_pool.cc
+++ b/net/socket/socks_client_socket_pool.cc
@@ -22,7 +22,7 @@ SOCKSSocketParams::SOCKSSocketParams(
RequestPriority priority,
const GURL& referrer)
: tcp_params_(proxy_server),
- destination_(host_port_pair.host, host_port_pair.port),
+ destination_(host_port_pair.host(), host_port_pair.port()),
socks_v5_(socks_v5) {
// The referrer is used by the DNS prefetch system to correlate resolutions
// with the page that triggered them. It doesn't impact the actual addresses
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index 2caa3fb..c2fedb2 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -23,7 +23,7 @@ namespace net {
TCPSocketParams::TCPSocketParams(const HostPortPair& host_port_pair,
RequestPriority priority, const GURL& referrer,
bool disable_resolver_cache)
- : destination_(host_port_pair.host, host_port_pair.port) {
+ : destination_(host_port_pair.host(), host_port_pair.port()) {
Initialize(priority, referrer, disable_resolver_cache);
}
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index d1ead09..c1216d7 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -7,6 +7,7 @@
#include "net/socket_stream/socket_stream.h"
+#include <set>
#include <string>
#include "base/compiler_specific.h"
@@ -487,9 +488,9 @@ int SocketStream::DoResolveHost() {
std::string host;
int port;
if (proxy_mode_ != kDirectConnection) {
- ProxyServer proxy_server = proxy_info_.proxy_server();
- host = proxy_server.HostNoBrackets();
- port = proxy_server.port();
+ HostPortPair host_port_pair = proxy_info_.proxy_server().host_port_pair();
+ host = host_port_pair.host();
+ port = host_port_pair.port();
} else {
host = url_.HostNoBrackets();
port = url_.EffectiveIntPort();
@@ -715,7 +716,7 @@ int SocketStream::DoReadTunnelHeadersComplete(int result) {
auth_info_ = new AuthChallengeInfo;
auth_info_->is_proxy = true;
auth_info_->host_and_port =
- ASCIIToWide(proxy_info_.proxy_server().host_and_port());
+ ASCIIToWide(proxy_info_.proxy_server().host_port_pair().ToString());
auth_info_->scheme = ASCIIToWide(auth_handler_->scheme());
auth_info_->realm = ASCIIToWide(auth_handler_->realm());
// Wait until RestartWithAuth or Close is called.
@@ -885,7 +886,8 @@ int SocketStream::DoReadWrite(int result) {
GURL SocketStream::ProxyAuthOrigin() const {
DCHECK(!proxy_info_.is_empty());
- return GURL("http://" + proxy_info_.proxy_server().host_and_port());
+ return GURL("http://" +
+ proxy_info_.proxy_server().host_port_pair().ToString());
}
int SocketStream::HandleAuthChallenge(const HttpResponseHeaders* headers) {
@@ -990,4 +992,3 @@ ProxyService* SocketStream::proxy_service() const {
}
} // namespace net
-
diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc
index 65a8068..25c9d24 100644
--- a/net/spdy/spdy_http_stream_unittest.cc
+++ b/net/spdy/spdy_http_stream_unittest.cc
@@ -11,7 +11,7 @@ namespace net {
class SpdyHttpStreamTest : public testing::Test {
protected:
- SpdyHttpStreamTest(){}
+ SpdyHttpStreamTest() {}
void EnableCompression(bool enabled) {
spdy::SpdyFramer::set_enable_compression_default(enabled);
@@ -48,9 +48,9 @@ TEST_F(SpdyHttpStreamTest, SendRequest) {
spdy_session_pool->Get(
host_port_pair, http_session.get(), BoundNetLog());
scoped_refptr<TCPSocketParams> tcp_params =
- new TCPSocketParams(host_port_pair.host, host_port_pair.port,
+ new TCPSocketParams(host_port_pair.host(), host_port_pair.port(),
MEDIUM, GURL(), false);
- int rv = session->Connect(host_port_pair.host, tcp_params, MEDIUM);
+ int rv = session->Connect(host_port_pair.host(), tcp_params, MEDIUM);
ASSERT_EQ(OK, rv);
HttpRequestInfo request;
diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc
index c012347..70c7863 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -79,9 +79,7 @@ TEST_F(SpdySessionTest, GoAway) {
const std::string kTestHost("www.foo.com");
const int kTestPort = 80;
- HostPortPair test_host_port_pair;
- test_host_port_pair.host = kTestHost;
- test_host_port_pair.port = kTestPort;
+ HostPortPair test_host_port_pair(kTestHost, kTestPort);
scoped_refptr<SpdySessionPool> spdy_session_pool(
http_session->spdy_session_pool());
@@ -145,9 +143,7 @@ TEST_F(SpdySessionTest, GetActivePushStream) {
const std::string kTestHost("www.foo.com");
const int kTestPort = 80;
- HostPortPair test_host_port_pair;
- test_host_port_pair.host = kTestHost;
- test_host_port_pair.port = kTestPort;
+ HostPortPair test_host_port_pair(kTestHost, kTestPort);
scoped_refptr<SpdySessionPool> spdy_session_pool(
http_session->spdy_session_pool());