From ecadbd7f18791b576e8a3ab1cae238748eeece38 Mon Sep 17 00:00:00 2001 From: Loic ANTOINE-GOMBEAUD Date: Wed, 12 Dec 2012 17:54:51 +0000 Subject: [CHEF-2682] raise exception on non-GET/HEAD redirects --- lib/chef/rest.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/chef/rest.rb') diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb index 21be437e24..85d6c5eafe 100644 --- a/lib/chef/rest.rb +++ b/lib/chef/rest.rb @@ -185,7 +185,11 @@ class Chef elsif response.kind_of?(Net::HTTPNotModified) # Must be tested before Net::HTTPRedirection because it's subclass. false elsif redirect_location = redirected_to(response) - follow_redirect {api_request(:GET, create_url(redirect_location))} + if [:GET, :HEAD].include?(method) + follow_redirect {api_request(method, create_url(redirect_location))} + else + raise Exceptions::InvalidRedirect, "#{method} request was redirected from #{url} to #{redirect_location}. Only GET and HEAD support redirects." + end else # have to decompress the body before making an exception for it. But the body could be nil. response.body.replace(response_body) if response.body.respond_to?(:replace) -- cgit v1.2.1