aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/request.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/request.rb')
-rw-r--r--lib/rubygems/request.rb24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb
index b2e9dbc679..00407971dd 100644
--- a/lib/rubygems/request.rb
+++ b/lib/rubygems/request.rb
@@ -21,7 +21,7 @@ class Gem::Request
@proxy_uri =
case proxy
when :no_proxy then nil
- when nil then get_proxy_from_env
+ when nil then get_proxy_from_env uri.scheme
when URI::HTTP then proxy
else URI.parse(proxy)
end
@@ -203,19 +203,27 @@ class Gem::Request
end
##
- # Returns an HTTP proxy URI if one is set in the environment variables.
+ # Returns a proxy URI for the given +scheme+ if one is set in the
+ # environment variables.
- def get_proxy_from_env
- env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
+ def get_proxy_from_env scheme = 'http'
+ _scheme = scheme.downcase
+ _SCHEME = scheme.upcase
+ env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"]
- return nil if env_proxy.nil? or env_proxy.empty?
+ no_env_proxy = env_proxy.nil? || env_proxy.empty?
+
+ return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http'
+ return nil if no_env_proxy
uri = URI(Gem::UriFormatter.new(env_proxy).normalize)
if uri and uri.user.nil? and uri.password.nil? then
- # Probably we have http_proxy_* variables?
- uri.user = Gem::UriFormatter.new(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']).escape
- uri.password = Gem::UriFormatter.new(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']).escape
+ user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"]
+ password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"]
+
+ uri.user = Gem::UriFormatter.new(user).escape
+ uri.password = Gem::UriFormatter.new(password).escape
end
uri