You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/09/24 00:57:30 UTC
svn commit: r1525726 - in /buildr/trunk: CHANGELOG
lib/buildr/core/transports.rb spec/core/transport_spec.rb
Author: donaldp
Date: Mon Sep 23 22:57:30 2013
New Revision: 1525726
URL: http://svn.apache.org/r1525726
Log:
Default to setting the "User-Agent" header to "Buildr-VERSION" when accessing http resources. Maven Central rejects requests without a User-Agent string.
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/lib/buildr/core/transports.rb
buildr/trunk/spec/core/transport_spec.rb
Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1525726&r1=1525725&r2=1525726&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Mon Sep 23 22:57:30 2013
@@ -1,4 +1,7 @@
1.4.13 (Pending)
+* Change: Default to setting the "User-Agent" header to "Buildr-VERSION"
+ when accessing http resources. Maven Central rejects requests
+ without a User-Agent string.
* Change: Change default scope of dependencies to 'compile'. Submitted
by Ingo Schmidt.
* Change: BUILDR-675 - Set Cache-Control to 'no-cache' when downloading
Modified: buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/transports.rb?rev=1525726&r1=1525725&r2=1525726&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/transports.rb (original)
+++ buildr/trunk/lib/buildr/core/transports.rb Mon Sep 23 22:57:30 2013
@@ -274,6 +274,7 @@ module URI
headers = {}
headers['If-Modified-Since'] = CGI.rfc1123_date(options[:modified].utc) if options[:modified]
headers['Cache-Control'] = 'no-cache'
+ headers['User-Agent'] = "Buildr-#{Buildr::VERSION}"
request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
request.basic_auth self.user, self.password if self.user
http.request request do |response|
Modified: buildr/trunk/spec/core/transport_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/transport_spec.rb?rev=1525726&r1=1525725&r2=1525726&view=diff
==============================================================================
--- buildr/trunk/spec/core/transport_spec.rb (original)
+++ buildr/trunk/spec/core/transport_spec.rb Mon Sep 23 22:57:30 2013
@@ -223,6 +223,10 @@ describe URI::FILE, '#write' do
end
+def default_http_headers
+ {"Cache-Control" => "no-cache", "User-Agent" => "Buildr-#{Buildr::VERSION}"}
+end
+
describe URI::HTTP, '#read' do
before do
@proxy = 'http://john:smith@myproxy:8080'
@@ -328,7 +332,7 @@ describe URI::HTTP, '#read' do
redirect['Location'] = "http://#{@host_domain}/asdf"
request1 = mock('request1')
- Net::HTTP::Get.should_receive(:new).once.with('/', {"Cache-Control"=>"no-cache"}).and_return(request1)
+ Net::HTTP::Get.should_receive(:new).once.with('/', default_http_headers).and_return(request1)
request1.should_receive(:basic_auth).with('john', 'secret')
@http.should_receive(:request).with(request1).and_yield(redirect)
@@ -337,7 +341,7 @@ describe URI::HTTP, '#read' do
ok.stub!(:read_body)
request2 = mock('request2')
- Net::HTTP::Get.should_receive(:new).once.with("/asdf", {"Cache-Control"=>"no-cache"}).and_return(request2)
+ Net::HTTP::Get.should_receive(:new).once.with("/asdf", default_http_headers).and_return(request2)
request2.should_receive(:basic_auth).with('john', 'secret')
@http.should_receive(:request).with(request2).and_yield(ok)
@@ -347,7 +351,7 @@ describe URI::HTTP, '#read' do
it 'should include the query part when performing HTTP GET' do
# should this test be generalized or shared with any other URI subtypes?
Net::HTTP.stub!(:new).and_return(@http)
- Net::HTTP::Get.should_receive(:new).with(/#{Regexp.escape(@query)}$/, {"Cache-Control"=>"no-cache"})
+ Net::HTTP::Get.should_receive(:new).with(/#{Regexp.escape(@query)}$/, default_http_headers)
@uri.read
end