I am using the PragProg 1.7.3 distro of ruby which includes zlib 0.5.1
I am trying to decode the response.body from an HTTP request.
Like this:
headers["Accept-encoding"] = "gzip"
uri = URI.parse(source)
h = Net::HTTP.new(uri.host)
resp = h.get(uri.path, headers)
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
resp.each {|key, val| printf "%-14s = %-40.40s\n", key, val }
data = resp.body
if resp.fetch('content-encoding', 'None') == 'gzip'
begin
pp data[0..2]
data = Zlib::Inflate.inflate(data)
rescue StandardError => err
print "Zlib error: #{err}\n"
end
end
This always results in : Zlib error: unknown compression method
Byte 2 of the string is \010 - which is correct.
Anyone seen this?
Thanks in advance.
-Jeff