summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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());