Skip to content

Commit 965d208

Browse files
committed
fixed error when response body is nil
1 parent 72673af commit 965d208

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/restclient/request.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def process_result res, &block
207207
end
208208

209209
def self.decode content_encoding, body
210-
if content_encoding == 'gzip' and not body.empty?
210+
if (!body) || body.empty?
211+
body
212+
elsif content_encoding == 'gzip'
211213
Zlib::GzipReader.new(StringIO.new(body)).read
212214
elsif content_encoding == 'deflate'
213215
Zlib::Inflate.new.inflate body

spec/request_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@
2626
end
2727

2828
describe "compression" do
29+
2930
it "decodes an uncompressed result body by passing it straight through" do
3031
RestClient::Request.decode(nil, 'xyz').should == 'xyz'
3132
end
3233

34+
it "doesn't fail for nil bodies" do
35+
RestClient::Request.decode('gzip', nil).should be_nil
36+
end
37+
38+
3339
it "decodes a gzip body" do
3440
RestClient::Request.decode('gzip', "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000").should == "i'm gziped\n"
3541
end

0 commit comments

Comments
 (0)