Skip to content

Commit

Permalink
HTTP(S) proxy support
Browse files Browse the repository at this point in the history
Determines whether an HTTP proxy has been configured and uses it if so.
  • Loading branch information
mojodna authored and mislav committed Jan 17, 2012
1 parent ebbb859 commit d789e80
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/hub/commands.rb
Expand Up @@ -944,7 +944,26 @@ def http_request(url, type = :Get)
port = 80
end

http = Net::HTTP.new(url.host, port)
# sniff out proxy settings
if use_ssl
proxy = ENV['HTTPS_PROXY'] || ENV['https_proxy']
else
proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
end

if proxy
# use an HTTP(S) proxy

unless /^[^:]+:\/\// =~ proxy
proxy = "http://#{proxy}"
end

proxy = URI.parse(proxy)
http = Net::HTTP.new(url.host, port, proxy.host, proxy.port, proxy.user, proxy.password)
else
http = Net::HTTP.new(url.host, port)
end

if http.use_ssl = use_ssl
# TODO: SSL peer verification
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand Down

0 comments on commit d789e80

Please sign in to comment.