diff options
author | danielsdeleo <dan@opscode.com> | 2013-11-05 12:29:01 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-11-05 12:48:47 -0800 |
commit | 82cbc9afc737eb8421db24f04f21ba50edc9ff3e (patch) | |
tree | 8183958fe15ccf0b18b0f50efca6eecbe0798753 | |
parent | aee24137198aaa577680206dfe0eb7fb04a95f8c (diff) | |
download | chef-82cbc9afc737eb8421db24f04f21ba50edc9ff3e.tar.gz |
Pass custom headers when following a redirect
Fixes CHEF-1848: https://tickets.opscode.com/browse/CHEF-1848
-rw-r--r-- | chef/lib/chef/rest.rb | 2 | ||||
-rw-r--r-- | chef/spec/unit/rest_spec.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index 5556800fcd..a3f36b8c4f 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -276,7 +276,7 @@ class Chef end elsif redirect_location = redirected_to(response) if [:GET, :HEAD].include?(method) - follow_redirect {api_request(method, create_url(redirect_location))} + follow_redirect {api_request(method, create_url(redirect_location), headers)} else raise Exceptions::InvalidRedirect, "#{method} request was redirected from #{url} to #{redirect_location}. Only GET and HEAD support redirects." end diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index 37e86e5462..bc7ad084e6 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -452,6 +452,10 @@ describe Chef::REST do @http_client.should_receive(:request).and_yield(redirect).and_return(redirect) @http_client.should_receive(:request).and_yield(success).and_return(success) + # CHEF-1848: verify that headers get passed to redirects + @rest.should_receive(:retriable_rest_request).with(:GET, @url, nil, expected_headers).and_call_original + @rest.should_receive(:retriable_rest_request).with(:GET, redirected_uri, nil, expected_headers).and_call_original + @rest.api_request(:GET, @url, headers).should == {"foo" => "bar"} end |