Skip to content

Commit

Permalink
Showing 2 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/ruby/2.0/net/http.rb
Original file line number Diff line number Diff line change
@@ -609,7 +609,7 @@ class << HTTP
# 'http.proxyHost' and 'http.proxyPort' Java system properties, if they
# are set and no alternative proxy has been provided.
#
def HTTP.new(address, port = nil, p_addr = ENV_JAVA['http.proxyHost'], p_port = ENV_JAVA['http.proxyPort'], p_user = nil, p_pass = nil)
def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil)
http = super address, port

if proxy_class? then # from Net::HTTP::Proxy()
47 changes: 40 additions & 7 deletions lib/ruby/2.0/uri/generic.rb
Original file line number Diff line number Diff line change
@@ -1638,11 +1638,7 @@ def find_proxy
proxy_uri = ENV["CGI_#{name.upcase}"]
end
elsif name == 'http_proxy'
unless proxy_uri = ENV[name]
if proxy_uri = ENV[name.upcase]
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
end
end
proxy_uri = http_proxy_from_env
else
proxy_uri = ENV[name] || ENV[name.upcase]
end
@@ -1660,8 +1656,7 @@ def find_proxy
end
end

name = 'no_proxy'
if no_proxy = ENV[name] || ENV[name.upcase]
if no_proxy = no_proxy_from_env
no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
(!port || self.port == port.to_i)
@@ -1671,5 +1666,43 @@ def find_proxy
end
URI.parse(proxy_uri)
end

def http_proxy_from_env
proxy_host = ENV_JAVA['http.proxyHost']

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

if proxy_uri.nil? || proxy_uri.empty?
proxy_uri = ENV['http_proxy']

if proxy_uri.nil? && (proxy_uri = ENV['HTTP_PROXY'])
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
end
end

proxy_uri
end
private :http_proxy_from_env

def no_proxy_from_env
no_proxy = ENV_JAVA['http.nonProxyHosts']

if no_proxy.nil? || no_proxy.empty?
name = "no_proxy"
no_proxy = ENV[name] || ENV[name.upcase]
end

no_proxy
end
private :no_proxy_from_env
end
end

0 comments on commit 35cf0da

Please sign in to comment.