summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-14 23:17:14 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-14 23:17:14 +0000
commite57ec6f78194e1cd7bb74b47cda1eab065e2d39a (patch)
treedc4d7f9e8b82e6c38bd37b7d2bd6d8e8cd879e2e /net
parente5a99ff3bd91f5493e7916b9dca6b29429ce0f43 (diff)
downloadchromium_src-e57ec6f78194e1cd7bb74b47cda1eab065e2d39a.zip
chromium_src-e57ec6f78194e1cd7bb74b47cda1eab065e2d39a.tar.gz
chromium_src-e57ec6f78194e1cd7bb74b47cda1eab065e2d39a.tar.bz2
Change the host() method of ProxyServer to strip the
square brackets around an IPv6 literal address. Rename the method HostNoBrackets() to be consistent with GURL's new HostNoBrackets() method. When resolving an address, use the new HostNoBrackets() method instead of host(). Part of this changelist was contributed by Paul Marks of Google. Original review: http://codereview.chromium.org/115342 R=eroman http://crbug.com/12005 TEST=covered by new test cases in unit test Review URL: http://codereview.chromium.org/114029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16123 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_network_transaction.cc4
-rw-r--r--net/proxy/proxy_server.cc7
-rw-r--r--net/proxy/proxy_server.h6
-rw-r--r--net/proxy/proxy_server_unittest.cc40
4 files changed, 51 insertions, 6 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 18c4d9f..5d0e733 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -594,11 +594,11 @@ int HttpNetworkTransaction::DoResolveHost() {
// Determine the host and port to connect to.
if (using_proxy_ || using_tunnel_) {
ProxyServer proxy_server = proxy_info_.proxy_server();
- host = proxy_server.host();
+ host = proxy_server.HostNoBrackets();
port = proxy_server.port();
} else {
// Direct connection
- host = request_->url.host();
+ host = request_->url.HostNoBrackets();
port = request_->url.EffectiveIntPort();
}
diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc
index 8cb1c17..0209a83 100644
--- a/net/proxy/proxy_server.cc
+++ b/net/proxy/proxy_server.cc
@@ -56,10 +56,15 @@ ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin,
} // namespace
-const std::string& ProxyServer::host() const {
+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());
+
+ // 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_;
}
diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h
index 0cf792c..a3d5ca8 100644
--- a/net/proxy/proxy_server.h
+++ b/net/proxy/proxy_server.h
@@ -48,8 +48,10 @@ class ProxyServer {
return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5;
}
- // Gets the host portion of the proxy server.
- const std::string& host() const;
+ // 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;
diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc
index 1625a18..ad3fad5 100644
--- a/net/proxy/proxy_server_unittest.cc
+++ b/net/proxy/proxy_server_unittest.cc
@@ -48,6 +48,44 @@ TEST(ProxyServerTest, FromURI) {
"PROXY foopy:10"
},
+ // IPv6 HTTP proxy URIs:
+ {
+ "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10", // No scheme.
+ "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:10",
+ 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"
+ },
+ {
+ "http://[3ffe:2a00:100:7031::1]", // No port.
+ "[3ffe:2a00:100:7031::1]:80",
+ net::ProxyServer::SCHEME_HTTP,
+ "3ffe:2a00:100:7031::1",
+ 80,
+ "[3ffe:2a00:100:7031::1]:80",
+ "PROXY [3ffe:2a00:100:7031::1]:80"
+ },
+ {
+ "http://[::192.9.5.5]",
+ "[::192.9.5.5]:80",
+ net::ProxyServer::SCHEME_HTTP,
+ "::192.9.5.5",
+ 80,
+ "[::192.9.5.5]:80",
+ "PROXY [::192.9.5.5]:80"
+ },
+ {
+ "http://[::FFFF:129.144.52.38]:80",
+ "[::FFFF:129.144.52.38]:80",
+ net::ProxyServer::SCHEME_HTTP,
+ "::FFFF:129.144.52.38",
+ 80,
+ "[::FFFF:129.144.52.38]:80",
+ "PROXY [::FFFF:129.144.52.38]:80"
+ },
+
// SOCKS4 proxy URIs:
{
"socks4://foopy", // No port.
@@ -95,7 +133,7 @@ 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.host());
+ 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_pac_string, uri.ToPacString());