From d789e8039884195d0db0036f73386f44cf509e1e Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Mon, 16 Jan 2012 16:26:01 -0800 Subject: [PATCH] HTTP(S) proxy support Determines whether an HTTP proxy has been configured and uses it if so. --- lib/hub/commands.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 934cd38d..1c78374b 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -944,7 +944,26 @@ help 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 -- GitLab