public
Rubygem
Description: Makes http fun! Also, makes consuming restful web services dead easy.
Homepage:
Clone URL: git://github.com/jnunemaker/httparty.git
Click here to lend your support to: httparty and make a donation at www.pledgie.com !
Treat nil or empty bodies specially to avoid blowing up during response parsing.
evri (author)
Wed Aug 27 13:38:19 -0700 2008
jnunemaker (committer)
Fri Oct 24 21:32:31 -0700 2008
commit  31ad4f91c8c234b15b0d415eb2c088f6838846dc
tree    7c214ed9d7df3205196c01124dcb61d6f99f48a3
parent  df9957cfa569c4a15230f5b2cda0a5d8f1b3e727
...
139
140
141
 
142
143
144
...
139
140
141
142
143
144
145
0
@@ -139,6 +139,7 @@ module HTTParty
0
       end
0
       
0
       def parse_response(body) #:nodoc:
0
+        return nil if body.nil? or body.empty?
0
         case @format
0
         when :xml
0
           Hash.from_xml(body)
...
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
0
@@ -141,5 +141,20 @@ describe HTTParty do
0
         Foo.send(:send_request, 'get', '/foo', :basic_auth => 'string')
0
       end.should raise_error(ArgumentError)
0
     end
0
+
0
+    it "should not attempt to parse empty responses" do
0
+      http = Net::HTTP.new('localhost', 80)
0
+      Foo.stub!(:http).and_return(http)
0
+      response = Net::HTTPNoContent.new("1.1", 204, "No content for you")
0
+      response.stub!(:body).and_return(nil)
0
+      http.stub!(:request).and_return(response)
0
+
0
+      Foo.headers.clear # clear out bogus settings from other specs
0
+      Foo.format :xml
0
+      Foo.send(:send_request, 'get', '/bar').should be_nil
0
+
0
+      response.stub!(:body).and_return("")
0
+      Foo.send(:send_request, 'get', 'bar').should be_nil
0
+    end
0
   end
0
 end
0
\ No newline at end of file

Comments