open-uri + Zlib: not in gzip format

A

Atoli Atoli

Hello,

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:

begin
resp = open(uri, @headers)
data = Zlib::GzipReader.new(StringIO.new(resp.read)).read
rescue StandardError => e
puts "#{e.message} / #{resp.meta['content-encoding']}"
end

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top