mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Treat nil or empty bodies specially to avoid blowing up during response parsing.
This commit is contained in:
parent
df9957cfa5
commit
31ad4f91c8
2 changed files with 16 additions and 0 deletions
|
@ -139,6 +139,7 @@ module HTTParty
|
|||
end
|
||||
|
||||
def parse_response(body) #:nodoc:
|
||||
return nil if body.nil? or body.empty?
|
||||
case @format
|
||||
when :xml
|
||||
Hash.from_xml(body)
|
||||
|
|
|
@ -141,5 +141,20 @@ describe HTTParty do
|
|||
Foo.send(:send_request, 'get', '/foo', :basic_auth => 'string')
|
||||
end.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should not attempt to parse empty responses" do
|
||||
http = Net::HTTP.new('localhost', 80)
|
||||
Foo.stub!(:http).and_return(http)
|
||||
response = Net::HTTPNoContent.new("1.1", 204, "No content for you")
|
||||
response.stub!(:body).and_return(nil)
|
||||
http.stub!(:request).and_return(response)
|
||||
|
||||
Foo.headers.clear # clear out bogus settings from other specs
|
||||
Foo.format :xml
|
||||
Foo.send(:send_request, 'get', '/bar').should be_nil
|
||||
|
||||
response.stub!(:body).and_return("")
|
||||
Foo.send(:send_request, 'get', 'bar').should be_nil
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue