Open-uri + Zlib: not in gzip format


I have a script that fetches a gzip compressed web page using open-uri
and Zlib.
It works well most of the time, but sometimes Zlib raises a
Zlib::GzipFile::Error exception saying that the data was not in gzip
format (even though the content-encoding was gzip).

The code basically looks like this:

  resp = open(uri, @headers)
  data =
rescue StandardError => e
  puts "#{e.message} / #{resp.meta['content-encoding']}"

I tried to dump the data to a file to see if I can inflate it with
gunzip. It worked. I then tried to reopen the file in ruby using Zlib
module, and it also worked.
If the server response was somehow corrupted I wouldn't be able to
gunzip the dumped file, right? Or did I miss something?

Thanks in advance.


Posted via