summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-07-27 16:46:46 -0700
committerPete Higgins <pete@peterhiggins.org>2020-07-27 16:52:54 -0700
commit09cdc96cb25956b3ef053fbe093d06453a7af92b (patch)
tree124a9fe7ece206b0955ff0c893b8c9d6d6b79f45
parent042ae378e449bb0499fdec015a374b859b9fc5b0 (diff)
downloadchef-09cdc96cb25956b3ef053fbe093d06453a7af92b.tar.gz
Fix NoMethodError when server returns a 406.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/http.rb7
-rw-r--r--spec/unit/server_api_spec.rb6
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 1777739a93..eed2a41815 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -58,7 +58,6 @@ class Chef
handler.handle_chunk(chunk)
end
end
-
end
def self.middlewares
@@ -471,7 +470,11 @@ class Chef
end
def version_retries
- @version_retries ||= options[:version_class].possible_requests
+ @version_retries ||= if options[:version_class]
+ options[:version_class].possible_requests
+ else
+ 0
+ end
end
# @api private
diff --git a/spec/unit/server_api_spec.rb b/spec/unit/server_api_spec.rb
index 3f1d9b0e90..1116eec9d9 100644
--- a/spec/unit/server_api_spec.rb
+++ b/spec/unit/server_api_spec.rb
@@ -121,4 +121,10 @@ describe Chef::ServerAPI do
client.get("foo")
end
end
+
+ it "does not retry a 406 Not Acceptable" do
+ WebMock.disable_net_connect!
+ stub_request(:get, "http://chef.example.com:4000/foo").to_return(status: [406, "Not Acceptable"])
+ expect { client.get("foo") }.to raise_error(Net::HTTPServerException)
+ end
end