diff options
author | danielsdeleo <dan@opscode.com> | 2013-11-15 15:08:40 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-11-15 15:08:40 -0800 |
commit | 43427bf41bcf07a04946b0a7435af78ec4955426 (patch) | |
tree | f964e9cfd4afb1c77cfb0acbd9a7b8584d7a9529 /lib/chef/cookbook_uploader.rb | |
parent | 5d2e306bfd4030a5c27bd8a0b13da686db3a6b8a (diff) | |
download | chef-43427bf41bcf07a04946b0a7435af78ec4955426.tar.gz |
Update HTTP usage for IPv6 Support
* Fixes Chef::HTTP related code to use URI::Generic#hostname when
initializing Net::HTTP objects.
* Replace RestClient usage in cookbook uploader with Chef::HTTP::Simple;
RestClient has the same bug as is fixed in the Chef::HTTP code (and is
difficult to fix with a monkey patch). See:
https://github.com/rest-client/rest-client/blob/0919b02cc57447cf42a67e31aad87ab2a6929da3/lib/restclient/request.rb#L150
* Manually verified with chef-zero; chef-zero's test helper code does
not expose the `:host` parameter so it cannot be used to bind the
server to ::1. Integration tests will be added once this is solved.
Diffstat (limited to 'lib/chef/cookbook_uploader.rb')
-rw-r--r-- | lib/chef/cookbook_uploader.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 3ead26e56d..34a982f0fb 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -137,7 +137,7 @@ class Chef timestamp = Time.now.utc.iso8601 file_contents = File.open(file, "rb") {|f| f.read} # TODO - 5/28/2010, cw: make signing and sending the request streaming - headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' } + headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, "accept" => 'application/json' } if rest.signing_key sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object( :http_method => :put, @@ -150,10 +150,12 @@ class Chef end begin - RestClient::Resource.new(url, :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents) + Chef::HTTP::Simple.new(url, :headers=>headers).put(url, file_contents) checksums_to_upload.delete(checksum) - rescue RestClient::Exception => e - Chef::Knife.ui.error("Failed to upload #@cookbook : #{e.message}\n#{e.response.body}") + rescue Net::HTTPServerException, Net::HTTPFatalError, Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError => e + error_message = "Failed to upload #{file} (#{checksum}) to #{url} : #{e.message}" + error_message << "\n#{e.response.body}" if e.respond_to?(:response) + Chef::Knife.ui.error(error_message) raise end end |