mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Merge commit 'jeg2/master'
This commit is contained in:
commit
4bd48d5005
2 changed files with 23 additions and 9 deletions
|
@ -119,7 +119,7 @@ module RestClient
|
|||
end
|
||||
|
||||
def process_result(res)
|
||||
if %w(200 201 202).include? res.code
|
||||
if res.code =~ /\A2\d{2}\z/
|
||||
decode res['content-encoding'], res.body
|
||||
elsif %w(301 302 303).include? res.code
|
||||
url = res.header['Location']
|
||||
|
@ -143,7 +143,7 @@ module RestClient
|
|||
end
|
||||
|
||||
def decode(content_encoding, body)
|
||||
if content_encoding == 'gzip'
|
||||
if content_encoding == 'gzip' and not body.empty?
|
||||
Zlib::GzipReader.new(StringIO.new(body)).read
|
||||
elsif content_encoding == 'deflate'
|
||||
Zlib::Inflate.new.inflate(body)
|
||||
|
|
|
@ -29,6 +29,10 @@ describe RestClient::Request do
|
|||
@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
|
||||
|
||||
it "ingores gzip for empty bodies" do
|
||||
@request.decode('gzip', '').should be_empty
|
||||
end
|
||||
|
||||
it "decodes a deflated body" do
|
||||
@request.decode('deflate', "x\234+\316\317MUHIM\313I,IMQ(I\255(\001\000A\223\006\363").should == "some deflated text"
|
||||
end
|
||||
|
@ -41,6 +45,16 @@ describe RestClient::Request do
|
|||
@request.process_result(res).should == 'body'
|
||||
end
|
||||
|
||||
it "doesn't classify successful requests as failed" do
|
||||
203.upto(206) do |code|
|
||||
res = mock("result")
|
||||
res.stub!(:code).and_return(code.to_s)
|
||||
res.stub!(:body).and_return("")
|
||||
res.stub!(:[]).with('content-encoding').and_return(nil)
|
||||
@request.process_result(res).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it "parses a url into a URI object" do
|
||||
URI.should_receive(:parse).with('http://example.com/resource')
|
||||
@request.parse_url('http://example.com/resource')
|
||||
|
|
Loading…
Add table
Reference in a new issue