summaryrefslogtreecommitdiff
path: root/lib/rubygems/request/connection_pools.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/request/connection_pools.rb')
-rw-r--r--lib/rubygems/request/connection_pools.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb
index 7a0a6e6e74..271b32b2b1 100644
--- a/lib/rubygems/request/connection_pools.rb
+++ b/lib/rubygems/request/connection_pools.rb
@@ -61,18 +61,22 @@ class Gem::Request::ConnectionPools # :nodoc:
end
def net_http_args uri, proxy_uri
- net_http_args = [uri.host, uri.port]
+ # URI::Generic#hostname was added in ruby 1.9.3, use it if exists, otherwise
+ # don't support IPv6 literals and use host.
+ hostname = uri.respond_to?(:hostname) ? uri.hostname : uri.host
+ net_http_args = [hostname, uri.port]
no_proxy = get_no_proxy_from_env
- if proxy_uri and not no_proxy?(uri.host, no_proxy) then
+ if proxy_uri and not no_proxy?(hostname, no_proxy) then
+ proxy_hostname = proxy_uri.respond_to?(:hostname) ? proxy_uri.hostname : proxy_uri.host
net_http_args + [
- proxy_uri.host,
+ proxy_hostname,
proxy_uri.port,
Gem::UriFormatter.new(proxy_uri.user).unescape,
Gem::UriFormatter.new(proxy_uri.password).unescape,
]
- elsif no_proxy? uri.host, no_proxy then
+ elsif no_proxy? hostname, no_proxy then
net_http_args + [nil, nil]
else
net_http_args