Skip to content

Commit

Permalink
Prefer ENV for proxy settings, because:
Browse files Browse the repository at this point in the history
* It is a new feature in 2.0+ stdlib, so our old logic using
  ENV_JAVA as default is now invalid.
* http.nonProxyHosts defaults to a non-empty value, making it
  impossible to fall back on ENV.

Fixes failing MRI test on master.
headius committed Jun 2, 2015
1 parent efe1e06 commit b0a41e7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/ruby/stdlib/uri/generic.rb
Original file line number Diff line number Diff line change
@@ -1550,37 +1550,38 @@ def find_proxy
end

def http_proxy_from_env
proxy_host = ENV_JAVA['http.proxyHost']
proxy_uri = ENV['http_proxy']

if proxy_host
begin
proxy_port = (ENV_JAVA['http.proxyPort'] || 80).to_i
if proxy_port > 0
proxy_uri = "http://#{proxy_host}:#{proxy_port}"
else
warn "invalid http.proxyPort property: #{ENV_JAVA['http.proxyPort']}"
end
end
if proxy_uri.nil? && (proxy_uri = ENV['HTTP_PROXY'])
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
end

if proxy_uri.nil? || proxy_uri.empty?
proxy_uri = ENV['http_proxy']
proxy_host = ENV_JAVA['http.proxyHost']

if proxy_uri.nil? && (proxy_uri = ENV['HTTP_PROXY'])
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
if proxy_host
begin
proxy_port = (ENV_JAVA['http.proxyPort'] || 80).to_i
if proxy_port > 0
proxy_uri = "http://#{proxy_host}:#{proxy_port}"
else
warn "invalid http.proxyPort property: #{ENV_JAVA['http.proxyPort']}"
end
end
end
end

proxy_uri
end
private :http_proxy_from_env

DEFAULT_JVM_NON_PROXY_HOSTS = "local|*.local|169.254/16|*.169.254/16|127.0.0.1|localhost|*.localhost"
def no_proxy_from_env
no_proxy = ENV_JAVA['http.nonProxyHosts']
name = "no_proxy"
no_proxy = ENV[name] || ENV[name.upcase]

if no_proxy.nil? || no_proxy.empty?
name = "no_proxy"
no_proxy = ENV[name] || ENV[name.upcase]
no_proxy = ENV_JAVA['http.nonProxyHosts']
end

no_proxy

0 comments on commit b0a41e7

Please sign in to comment.