From c7aed1a6a1e179a198d8899bfd6dab21f309bf22 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 28 Jul 2013 20:06:36 -0300 Subject: [PATCH] Provide a custom user agent header to cURL request so that URL shorteners are able to track the amount of downloads --- lib/vagrant/util/downloader.rb | 5 +++++ test/unit/vagrant/util/downloader_test.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index ccf483b94..2db2c56c7 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -9,6 +9,10 @@ module Vagrant # to cURL. cURL is a much more capable and complete download tool than # a hand-rolled Ruby library, so we defer to it's expertise. class Downloader + # Custom user agent provided to cURL so that requests to URL shorteners + # are properly tracked. + USER_AGENT = "Vagrant cURL Downloader" + def initialize(source, destination, options=nil) @logger = Log4r::Logger.new("vagrant::util::downloader") @source = source.to_s @@ -32,6 +36,7 @@ module Vagrant "--fail", "--location", "--max-redirs", "10", + "--user-agent", USER_AGENT, "--output", @destination ] diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 8e45c082d..7968700b1 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -25,7 +25,7 @@ describe Vagrant::Util::Downloader do let(:exit_code) { 0 } it "downloads the file and returns true" do - curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}] + curl_options = ["--fail", "--location", "--max-redirs", "10", "--user-agent", described_class::USER_AGENT, "--output", destination, source, {}] Vagrant::Util::Subprocess.should_receive(:execute). with("curl", *curl_options). @@ -39,7 +39,7 @@ describe Vagrant::Util::Downloader do let(:exit_code) { 1 } it "raises an exception" do - curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}] + curl_options = ["--fail", "--location", "--max-redirs", "10", "--user-agent", described_class::USER_AGENT, "--output", destination, source, {}] Vagrant::Util::Subprocess.should_receive(:execute). with("curl", *curl_options).