From d4c753c48d0838cf9cbdc0777bf070ac53d36a3b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 7 Feb 2014 10:30:25 -0800 Subject: [PATCH] core: download metadata with JSON accept header --- lib/vagrant/action/builtin/box_add.rb | 3 ++- lib/vagrant/util/downloader.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 891e05145..867e981bb 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -134,7 +134,7 @@ module Vagrant metadata = nil begin - metadata_path = download(url, env, ui: false) + metadata_path = download(url, env, json: true, ui: false) File.open(metadata_path) do |f| metadata = BoxMetadata.new(f) @@ -391,6 +391,7 @@ module Vagrant downloader_options[:continue] = true downloader_options[:insecure] = env[:box_download_insecure] downloader_options[:client_cert] = env[:box_client_cert] + downloader_options[:headers] = ["Accept: application/json"] if opts[:json] downloader_options[:ui] = env[:ui] if opts[:ui] Util::Downloader.new(url, temp_path, downloader_options) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index 69f1e8700..b87e95a83 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -26,6 +26,7 @@ module Vagrant options ||= {} @ca_cert = options[:ca_cert] @continue = options[:continue] + @headers = options[:headers] @insecure = options[:insecure] @ui = options[:ui] @client_cert = options[:client_cert] @@ -180,6 +181,12 @@ module Vagrant options << "--insecure" if @insecure options << "--cert" << @client_cert if @client_cert + if @headers + Array(@headers).each do |header| + options << "-H" << header + end + end + # Specify some options for the subprocess subprocess_options = {}