Commit 9db2c80b authored by danielsdeleo's avatar danielsdeleo
Browse files

Do not attempt to JSON parse the body of a 204 response.

An HTTP 204 No Content response may have a Content-Type header even
though it has no content--this is not disallowed by the RFC. Update
Chef::REST to handle this case and not attempt to parse the (nil)
parent 8a1a44bf
......@@ -267,7 +267,11 @@ class Chef
response_body = decompress_body(response)
if response.kind_of?(Net::HTTPSuccess)
# 204 is successful, Net::HTTP returns nil response body.
# Don't attempt to parse it.
if response.kind_of?(Net::HTTPNoContent)
elsif response.kind_of?(Net::HTTPSuccess)
if response['content-type'] =~ /json/
......@@ -422,6 +422,21 @@ describe Chef::REST do
@rest.api_request(:GET, @url).should == "ninja"
it "returns nil when the response is a 204 and the content-type is JSON" do
@http_response ="1.1", "204", "successful rest req")
@http_response.add_field("Content-Length", "0")
@http_response.add_field("Content-Type", "application/json")
@http_client =, @url.port)
@rest.api_request(:GET, @url).should be_nil
it "should inflate the body as to an object if JSON is returned" do
@http_response.add_field('content-type', "application/json")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment