jnunemaker/httparty — pull request #227 by bradcater (2013-08-03 15:47:28+00:00)
Title: Fix a bug in which we attempt to decompress the body on HEAD requests

Doing a HEAD request to a compressed asset causes an error when we try to decompress the body of the response in `handle_deflation` in _lib/httparty/request.rb_. A simple test case does a HEAD request to a compressed asset:

```ruby
HTTParty.head('http://production-assets0.betterifbox.com/stylesheets/splitlanding_packaged-d442280b4bb7e7cfc99f3ca42de29458.gz.css')
TypeError: can't convert nil into String
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty/request.rb:193:in `initialize'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty/request.rb:193:in `new'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty/request.rb:193:in `handle_deflation'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty/request.rb:105:in `perform'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty.rb:461:in `perform_request'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty.rb:444:in `head'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/httparty-0.11.0/lib/httparty.rb:521:in `head'
from (irb):1
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/railties-3.0.20/lib/rails/commands/console.rb:44:in `start'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/railties-3.0.20/lib/rails/commands/console.rb:8:in `start'
from /home/bradcater/.rvm/gems/ruby-1.9.3-p327-exp/gems/railties-3.0.20/lib/rails/commands.rb:23:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'
```

Skipping `handle_deflation` on HEAD requests prevents this error:

```ruby
HTTParty.head('http://production-assets0.betterifbox.com/stylesheets/splitlanding_packaged-d442280b4bb7e7cfc99f3ca42de29458.gz.css')
=> #, @headers={"content-type"=>["text/css"], "content-length"=>["14091"], "connection"=>["close"], "date"=>["Sat, 03 Aug 2013 03:13:28 GMT"], "cache-control"=>["max-age=315576000"], "content-encoding"=>["gzip"], "expires"=>["Thu, 24 Jul 2014 18:39:32 GMT"], "last-modified"=>["Wed, 24 Jul 2013 18:39:33 GMT"], "etag"=>["\"8ed02ea130ced1dc529756ca877482a1\""], "accept-ranges"=>["bytes"], "server"=>["AmazonS3"], "age"=>["44908"], "via"=>["1.0 87e19640fd6befc13bd3c90914982892.cloudfront.net (CloudFront)"], "x-cache"=>["Hit from cloudfront"], "x-amz-cf-id"=>["1hTQ1_icUPgeeW5fejXZ6nnMoB8eMe4DRBS4rmcpfK9AFP0Q5_qF0A=="]}>
```

I'm not sure how to test this with RSpec since testing this specific asset introduces an unnecessary external dependency. If you know the right way to test this, I'll add an appropriate spec.