Add an optional argument, env, to URI.find_proxy.
* lib/uri/generic.rb (URI.find_proxy): Add an optional argument, env. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ea8990d867
commit
1ab0740838
@ -1,3 +1,7 @@
|
||||
Tue Oct 11 16:45:24 2016 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/uri/generic.rb (URI.find_proxy): Add an optional argument, env.
|
||||
|
||||
Tue Oct 11 16:38:32 2016 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/pp.rb (String#pretty_print): Defined to print a string as
|
||||
|
@ -1486,6 +1486,8 @@ module URI
|
||||
# ftp_proxy, no_proxy, etc.
|
||||
# If there is no proper proxy, nil is returned.
|
||||
#
|
||||
# If the optional parameter, +env+, is specified, it is used instead of ENV.
|
||||
#
|
||||
# Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.)
|
||||
# are examined too.
|
||||
#
|
||||
@ -1494,41 +1496,41 @@ module URI
|
||||
# So HTTP_PROXY is not used.
|
||||
# http_proxy is not used too if the variable is case insensitive.
|
||||
# CGI_HTTP_PROXY can be used instead.
|
||||
def find_proxy
|
||||
def find_proxy(env=ENV)
|
||||
raise BadURIError, "relative URI: #{self}" if self.relative?
|
||||
name = self.scheme.downcase + '_proxy'
|
||||
proxy_uri = nil
|
||||
if name == 'http_proxy' && ENV.include?('REQUEST_METHOD') # CGI?
|
||||
if name == 'http_proxy' && env.include?('REQUEST_METHOD') # CGI?
|
||||
# HTTP_PROXY conflicts with *_proxy for proxy settings and
|
||||
# HTTP_* for header information in CGI.
|
||||
# So it should be careful to use it.
|
||||
pairs = ENV.reject {|k, v| /\Ahttp_proxy\z/i !~ k }
|
||||
pairs = env.reject {|k, v| /\Ahttp_proxy\z/i !~ k }
|
||||
case pairs.length
|
||||
when 0 # no proxy setting anyway.
|
||||
proxy_uri = nil
|
||||
when 1
|
||||
k, _ = pairs.shift
|
||||
if k == 'http_proxy' && ENV[k.upcase] == nil
|
||||
if k == 'http_proxy' && env[k.upcase] == nil
|
||||
# http_proxy is safe to use because ENV is case sensitive.
|
||||
proxy_uri = ENV[name]
|
||||
proxy_uri = env[name]
|
||||
else
|
||||
proxy_uri = nil
|
||||
end
|
||||
else # http_proxy is safe to use because ENV is case sensitive.
|
||||
proxy_uri = ENV.to_hash[name]
|
||||
proxy_uri = env.to_hash[name]
|
||||
end
|
||||
if !proxy_uri
|
||||
# Use CGI_HTTP_PROXY. cf. libwww-perl.
|
||||
proxy_uri = ENV["CGI_#{name.upcase}"]
|
||||
proxy_uri = env["CGI_#{name.upcase}"]
|
||||
end
|
||||
elsif name == 'http_proxy'
|
||||
unless proxy_uri = ENV[name]
|
||||
if proxy_uri = ENV[name.upcase]
|
||||
unless proxy_uri = env[name]
|
||||
if proxy_uri = env[name.upcase]
|
||||
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
|
||||
end
|
||||
end
|
||||
else
|
||||
proxy_uri = ENV[name] || ENV[name.upcase]
|
||||
proxy_uri = env[name] || env[name.upcase]
|
||||
end
|
||||
|
||||
if proxy_uri.nil? || proxy_uri.empty?
|
||||
|
Loading…
x
Reference in New Issue
Block a user