diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a3c90a8..2daa5702f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ available. [GH-556] - NFS should work for FreeBSD hosts now. [GH-510] - SSH executed methods respect `config.ssh.max_tries`. [GH-508] + - `vagrant box add` now respects the "no_proxy" environmental variable. + [GH-502] ## 0.8.7 (September 13, 2011) diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index f568fe2f9..6f0115feb 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -16,10 +16,9 @@ module Vagrant end def download!(source_url, destination_file) - uri = URI.parse(source_url) proxy_uri = resolve_proxy(uri) - + http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) if uri.scheme == "https" @@ -76,16 +75,23 @@ module Vagrant private + # This method respects the "http_proxy" and "no_proxy" environmental + # variables so that HTTP proxies can properly be used with Vagrant. def resolve_proxy(source_uri) - proxy_string = nil - if ENV['no_proxy'] && ENV['no_proxy'].split(',').any? { |h| source_uri.host =~ /#{Regexp.quote(h.strip)}$/ } - proxy_string = '' - else - proxy_string = ENV["http_proxy"] || '' - end - URI.parse(proxy_string) - end + proxy_string = ENV["http_proxy"] || "" + if !proxy_string.empty? && ENV.has_key?("no_proxy") + # Respect the "no_proxy" environmental variable which contains a list + # of hosts that a proxy should not be used for. + ENV["no_proxy"].split(",").each do |host| + if source_uri.host =~ /#{Regexp.quote(host.strip)}$/ + proxy_string = "" + break + end + end + end + URI.parse(proxy_string) + end end end end