Added Basic Auth support to HTTP downloader.
This commit is contained in:
parent
28cc13ad38
commit
dab80649b8
|
@ -2,6 +2,7 @@ require 'net/http'
|
|||
require 'net/https'
|
||||
require 'open-uri'
|
||||
require 'uri'
|
||||
require 'base64'
|
||||
|
||||
module Vagrant
|
||||
module Downloaders
|
||||
|
@ -27,7 +28,12 @@ module Vagrant
|
|||
http.start do |h|
|
||||
env.ui.info I18n.t("vagrant.downloaders.http.download", :url => source_url)
|
||||
|
||||
h.request_get(uri.request_uri) do |response|
|
||||
headers = nil
|
||||
if uri.user && uri.password
|
||||
headers = {'Authorization' => 'Basic ' + Base64.encode64(uri.user + ':' + uri.password)}
|
||||
end
|
||||
|
||||
h.request_get(uri.request_uri, headers) do |response|
|
||||
if response.is_a?(Net::HTTPRedirection)
|
||||
# Follow the HTTP redirect.
|
||||
# TODO: Error on some redirect limit
|
||||
|
|
|
@ -6,6 +6,7 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
|||
@downloader.stubs(:report_progress)
|
||||
@downloader.stubs(:complete_progress)
|
||||
@uri = "http://google.com/"
|
||||
@headers = nil
|
||||
end
|
||||
|
||||
context "downloading" do
|
||||
|
@ -48,7 +49,7 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
|||
segment.stubs(:length).returns(7)
|
||||
|
||||
@http.stubs(:start).yields(h)
|
||||
h.expects(:request_get).with(@parsed_uri.request_uri).once.yields(response)
|
||||
h.expects(:request_get).with(@parsed_uri.request_uri, @headers).once.yields(response)
|
||||
response.expects(:read_body).once.yields(segment)
|
||||
@tempfile.expects(:write).with(segment).once
|
||||
|
||||
|
|
Loading…
Reference in New Issue