Permalink
Browse files

HTTParty doesn't automatically deflate responses with a Content-Encod…

…ing: x-gzip header; it only works with Content-Encoding: gzip. This fixes it to work with both.
  • Loading branch information...
pgib committed Mar 23, 2012
1 parent 8fe9fda commit 777493ecdf09eb7e8efa0ec2326331f67d9b6fc3
Showing with 10 additions and 2 deletions.
  1. +1 −1 lib/httparty/request.rb
  2. +9 −1 spec/httparty/request_spec.rb
View
@@ -196,7 +196,7 @@ def handle_response
# Inspired by Ruby 1.9
def handle_deflation
case last_response["content-encoding"]
- when "gzip"
+ when "gzip", "x-gzip"
body_io = StringIO.new(last_response.body)
last_response.body.replace Zlib::GzipReader.new(body_io).read
last_response.delete('content-encoding')
@@ -495,14 +495,22 @@
@last_response.stub!(:body).and_return('')
end
- it "should inflate the gzipped body" do
+ it "should inflate the gzipped body with content-encoding: gzip" do
@last_response.stub!(:[]).with("content-encoding").and_return("gzip")
@request.stub!(:last_response).and_return(@last_response)
Zlib::GzipReader.should_receive(:new).and_return(StringIO.new(''))
@request.last_response.should_receive(:delete).with('content-encoding')
@request.send(:handle_deflation)
end
+ it "should inflate the gzipped body with content-encoding: x-gzip" do
+ @last_response.stub!(:[]).with("content-encoding").and_return("x-gzip")
+ @request.stub!(:last_response).and_return(@last_response)
+ Zlib::GzipReader.should_receive(:new).and_return(StringIO.new(''))
+ @request.last_response.should_receive(:delete).with('content-encoding')
+ @request.send(:handle_deflation)
+ end
+
it "should inflate the deflated body" do
@last_response.stub!(:[]).with("content-encoding").and_return("deflate")
@request.stub!(:last_response).and_return(@last_response)

0 comments on commit 777493e

Please sign in to comment.