From 5703407d41822d5a6efb9df18cab56e0e2e4f390 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 22 Aug 2014 11:55:25 -0700 Subject: response.body may be nil we can get back things like http 204 with no response body and calling chomp on that throws a bad stack track. this sends nil back with the response and the caller can determine how to handle the 204. --- lib/chef/http/json_output.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/chef/http') diff --git a/lib/chef/http/json_output.rb b/lib/chef/http/json_output.rb index 7a3b9c8638..069eb6a87f 100644 --- a/lib/chef/http/json_output.rb +++ b/lib/chef/http/json_output.rb @@ -26,6 +26,9 @@ class Chef # Middleware that takes an HTTP response, parses it as JSON if possible. class JSONOutput + attr_accessor :raw_output + attr_accessor :inflate_json_class + def initialize(opts={}) @raw_output = opts[:raw_output] @inflate_json_class = opts[:inflate_json_class] @@ -44,10 +47,12 @@ class Chef # needed to keep conditional get stuff working correctly. return [http_response, rest_request, return_value] if return_value == false if http_response['content-type'] =~ /json/ - if @raw_output + if http_response.body.nil? + return_value = nil + elsif raw_output return_value = http_response.body.to_s else - if @inflate_json_class + if inflate_json_class return_value = Chef::JSONCompat.from_json(http_response.body.chomp) else return_value = Chef::JSONCompat.parse(http_response.body.chomp) -- cgit v1.2.1