mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
fixed error when response body is nil
This commit is contained in:
parent
72673af123
commit
965d20899e
2 changed files with 9 additions and 1 deletions
|
@ -207,7 +207,9 @@ module RestClient
|
|||
end
|
||||
|
||||
def self.decode content_encoding, body
|
||||
if content_encoding == 'gzip' and not body.empty?
|
||||
if (!body) || body.empty?
|
||||
body
|
||||
elsif content_encoding == 'gzip'
|
||||
Zlib::GzipReader.new(StringIO.new(body)).read
|
||||
elsif content_encoding == 'deflate'
|
||||
Zlib::Inflate.new.inflate body
|
||||
|
|
|
@ -26,10 +26,16 @@ describe RestClient::Request do
|
|||
end
|
||||
|
||||
describe "compression" do
|
||||
|
||||
it "decodes an uncompressed result body by passing it straight through" do
|
||||
RestClient::Request.decode(nil, 'xyz').should == 'xyz'
|
||||
end
|
||||
|
||||
it "doesn't fail for nil bodies" do
|
||||
RestClient::Request.decode('gzip', nil).should be_nil
|
||||
end
|
||||
|
||||
|
||||
it "decodes a gzip body" do
|
||||
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"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue