ruby-changes:44319
From: akr <ko1@a...>
Date: Tue, 11 Oct 2016 16:54:02 +0900 (JST)
Subject: [ruby-changes:44319] akr:r56392 (trunk): Add an optional argument, env, to URI.find_proxy.
akr 2016-10-11 16:53:56 +0900 (Tue, 11 Oct 2016) New Revision: 56392 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56392 Log: Add an optional argument, env, to URI.find_proxy. * lib/uri/generic.rb (URI.find_proxy): Add an optional argument, env. Modified files: trunk/ChangeLog trunk/lib/uri/generic.rb Index: lib/uri/generic.rb =================================================================== --- lib/uri/generic.rb (revision 56391) +++ lib/uri/generic.rb (revision 56392) @@ -1486,6 +1486,8 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1486 # 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 https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1496 # 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? Index: ChangeLog =================================================================== --- ChangeLog (revision 56391) +++ ChangeLog (revision 56392) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Oct 11 16:45:24 2016 Tanaka Akira <akr@f...> + + * lib/uri/generic.rb (URI.find_proxy): Add an optional argument, env. + Tue Oct 11 16:38:32 2016 Tanaka Akira <akr@f...> * lib/pp.rb (String#pretty_print): Defined to print a string as -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/