“unknown compression method” with open-uri

In my local build of ruby 2.1.1 I see “unknown compression method” when calling open on certain URLs…

net/http/response.rb:357:in finish': unknown compression method (Zlib::DataError)

It looks like open-uri adds the header saying it can accept gzip and deflate (Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3) but if deflate is sent it blows up.

# broken - defaults to "Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3" but cannot deal with deflate

# fixed, only accept gzip
open("http://www.wunderground.com//q/zmw:00000.1.03334", "Accept-Encoding" => "gzip").read
Categorized as geek

Leave a comment

Your email address will not be published.