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 'net/https'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'base64'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Downloaders
|
module Downloaders
|
||||||
|
@ -27,7 +28,12 @@ module Vagrant
|
||||||
http.start do |h|
|
http.start do |h|
|
||||||
env.ui.info I18n.t("vagrant.downloaders.http.download", :url => source_url)
|
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)
|
if response.is_a?(Net::HTTPRedirection)
|
||||||
# Follow the HTTP redirect.
|
# Follow the HTTP redirect.
|
||||||
# TODO: Error on some redirect limit
|
# TODO: Error on some redirect limit
|
||||||
|
|
|
@ -6,6 +6,7 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
||||||
@downloader.stubs(:report_progress)
|
@downloader.stubs(:report_progress)
|
||||||
@downloader.stubs(:complete_progress)
|
@downloader.stubs(:complete_progress)
|
||||||
@uri = "http://google.com/"
|
@uri = "http://google.com/"
|
||||||
|
@headers = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
context "downloading" do
|
context "downloading" do
|
||||||
|
@ -48,7 +49,7 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
||||||
segment.stubs(:length).returns(7)
|
segment.stubs(:length).returns(7)
|
||||||
|
|
||||||
@http.stubs(:start).yields(h)
|
@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)
|
response.expects(:read_body).once.yields(segment)
|
||||||
@tempfile.expects(:write).with(segment).once
|
@tempfile.expects(:write).with(segment).once
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue