summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-11-25 16:50:14 -0800
committerdanielsdeleo <dan@opscode.com>2013-11-25 16:50:14 -0800
commitb3983fbb49fb15e61840fc1535e4c7c4f0906636 (patch)
tree433001ff5dfa3efe8e3627e1287a583fd31453de
parentfe1fd66bcea4b11e31c548cab54589e505217388 (diff)
parent8f65963c38cd35c9703991e5d8e24ada07902ec4 (diff)
downloadchef-b3983fbb49fb15e61840fc1535e4c7c4f0906636.tar.gz
Merge branch 's3-auth-regression-fix' into 10-stable
-rw-r--r--chef/lib/chef/rest.rb2
-rw-r--r--chef/spec/unit/rest_spec.rb30
2 files changed, 31 insertions, 1 deletions
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb
index 7ccdd43702..f61801f730 100644
--- a/chef/lib/chef/rest.rb
+++ b/chef/lib/chef/rest.rb
@@ -447,7 +447,7 @@ class Chef
headers = @default_headers.merge(headers)
#headers['Accept'] = "application/json" unless raw
headers['Accept'] = "application/json" unless raw
- headers["Content-Type"] = 'application/json' if json_body
+ headers["Content-Type"] = 'application/json' if json_body && !headers.keys.map(&:downcase).include?("content-type")
headers['Content-Length'] = json_body.bytesize.to_s if json_body
headers[RESTRequest::ACCEPT_ENCODING] = RESTRequest::ENCODING_GZIP_DEFLATE unless gzip_disabled?
headers.merge!(authentication_headers(method, url, json_body)) if sign_requests?
diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb
index 84f81a195c..91c994a816 100644
--- a/chef/spec/unit/rest_spec.rb
+++ b/chef/spec/unit/rest_spec.rb
@@ -423,6 +423,36 @@ describe Chef::REST do
@rest.api_request(:GET, @url, {}).should == {"ohai2u"=>"json_api"}
end
+ context "when sending a request with a body and the content-type isn't JSON" do
+
+ let(:expected_headers) do
+ @base_headers.merge("content-type" => 'application/x-binary', 'Content-Length' => '13')
+ end
+
+ let(:request_headers) do
+ {"content-type" => 'application/x-binary'}
+ end
+
+ let(:request_body) do
+ Chef::JSONCompat.to_json({:one=>:two})
+ end
+
+ it "should build a new HTTP POST request" do
+ request = Net::HTTP::Post.new(@url.path)
+ Net::HTTP::Post.should_receive(:new).with("/?foo=bar", expected_headers).and_return(request)
+ @rest.raw_http_request(:POST, @url, request_headers, request_body)
+ request.body.should == '{"one":"two"}'
+ end
+
+ it "should build a new HTTP PUT request" do
+ request = Net::HTTP::Put.new(@url.path)
+ Net::HTTP::Put.should_receive(:new).with("/?foo=bar",expected_headers).and_return(request)
+ @rest.raw_http_request(:PUT, @url, request_headers, request_body)
+ request.body.should == '{"one":"two"}'
+ end
+
+ end
+
describe "when the server returns a redirect response" do
let(:redirected_url) { "https://chef.example.com:8443/foo" }
let(:redirected_uri) { URI.parse(redirected_url) }