diff options
author | sdelano <stephen@opscode.com> | 2011-04-06 15:51:34 -0700 |
---|---|---|
committer | sdelano <stephen@opscode.com> | 2011-04-06 15:51:34 -0700 |
commit | 024a8cead2e8b70b315d99559b9f8e7f17fd09ab (patch) | |
tree | 7b70cca2c7919695adb8bd703c264cf51a115a4a | |
parent | abd5013411e4902264cd212fac29b2f7e8e16a83 (diff) | |
parent | 504c44c16a4be4c8f23bae5d0a3d4aa2a5fc045a (diff) | |
download | chef-024a8cead2e8b70b315d99559b9f8e7f17fd09ab.tar.gz |
Merge branch 'CHEF-2189'
-rw-r--r-- | chef/lib/chef/rest.rb | 1 | ||||
-rw-r--r-- | chef/spec/unit/rest_spec.rb | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index 2cf701c9e3..adf180a645 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -367,6 +367,7 @@ class Chef headers["Content-Type"] = 'application/json' if json_body headers['Content-Length'] = json_body.bytesize.to_s if json_body headers.merge!(authentication_headers(method, url, json_body)) if sign_requests? + headers.merge!(Chef::Config[:custom_http_headers]) if Chef::Config[:custom_http_headers] headers end diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index de23f8b45d..8a9105c1d6 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -316,6 +316,27 @@ describe Chef::REST do @request_mock['User-Agent'].should match /^Chef Client\/#{Chef::VERSION}/ end + context "when configured with custom http headers" do + before(:each) do + @custom_headers = { + 'X-Custom-ChefSecret' => 'sharpknives', + 'X-Custom-RequestPriority' => 'extremely low' + } + Chef::Config[:custom_http_headers] = @custom_headers + end + + after(:each) do + Chef::Config[:custom_http_headers] = nil + end + + it "should set them on the http request" do + url_string = an_instance_of(String) + header_hash = hash_including(@custom_headers) + Net::HTTP::Get.should_receive(:new).with(url_string, header_hash) + @rest.api_request(:GET, @url, {}) + end + end + it "should set the cookie for this request if one exists for the given host:port" do Chef::REST::CookieJar.instance["#{@url.host}:#{@url.port}"] = "cookie monster" Net::HTTP::Get.should_receive(:new).with("/?foo=bar", |