case resp
when Net::HTTPSuccess
+ debug resp.to_hash
+
if resp['content-type'] =~ /^text\/|(?:x|ht)ml/
# The page is text or HTML, so we can try finding a title and, if
# requested, the first par.
# if nothing was found, provide more basic info, as for non-html pages
end
- debug resp.to_hash.inspect
-
enc = resp['content-encoding']
extra << ", #{Bold}encoding#{Bold}: #{enc}" if enc
return str
when 'gzip', 'x-gzip'
debug "gunzipping body"
- return Zlib::GzipReader.new(StringIO.new(str)).read
+ begin
+ return Zlib::GzipReader.new(StringIO.new(str)).read
+ rescue Zlib::Error => e
+ # If we can't unpack the whole stream (e.g. because we're doing a
+ # partial read
+ debug "full gunzipping failed (#{e}), trying to recover as much as possible"
+ ret = ""
+ begin
+ Zlib::GzipReader.new(StringIO.new(str)).each_byte { |byte|
+ ret << byte
+ }
+ rescue
+ end
+ return ret
+ end
else
raise "Unhandled content encoding #{method}"
end