Allow downloading via a proxy if http_proxy environment variable is set. [closes GH-157]
This commit is contained in:
parent
65eaca09bc
commit
650ff4b734
|
@ -1,5 +1,7 @@
|
|||
## 0.6.0 (unreleased)
|
||||
|
||||
- If `http_proxy` environmental variable is set, it will be used as the proxy
|
||||
box adding via http.
|
||||
- Remove `config.ssh.password`. It hasn't been used for a few versions
|
||||
now and was only kept around to avoid exceptions in Vagrantfiles.
|
||||
- Configuration is now validated so improper input can be found in
|
||||
|
|
|
@ -15,8 +15,10 @@ module Vagrant
|
|||
end
|
||||
|
||||
def download!(source_url, destination_file)
|
||||
proxy_uri = URI.parse(ENV["http_proxy"] || "")
|
||||
uri = URI.parse(source_url)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
||||
|
||||
if uri.scheme == "https"
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
|
|
|
@ -10,6 +10,8 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
|||
|
||||
context "downloading" do
|
||||
setup do
|
||||
ENV["http_proxy"] = nil
|
||||
|
||||
@parsed_uri = URI.parse(@uri)
|
||||
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
|
||||
Net::HTTP.stubs(:new).returns(@http)
|
||||
|
@ -17,7 +19,15 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "create a proper net/http object" do
|
||||
Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port).once.returns(@http)
|
||||
Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port, nil, nil, nil, nil).once.returns(@http)
|
||||
@http.expects(:start)
|
||||
@downloader.download!(@uri, @tempfile)
|
||||
end
|
||||
|
||||
should "create a proper net/http object with a proxy" do
|
||||
ENV["http_proxy"] = "http://user:foo@google.com"
|
||||
@proxy = URI.parse(ENV["http_proxy"])
|
||||
Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password).once.returns(@http)
|
||||
@http.expects(:start)
|
||||
@downloader.download!(@uri, @tempfile)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue