def decompress_body(str)
method = self['content-encoding']
case method
when nil
return str
when /gzip/
debug "gunzipping body"
begin
return Zlib::GzipReader.new(StringIO.new(str)).read
rescue Zlib::Error => e
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
when 'deflate'
debug "inflating body"
inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
begin
return inflater.inflate(str)
rescue Zlib::Error => e
raise e
end
when /^(?:iso-8859-\d+|windows-\d+|utf-8|utf8)$/i
old_hsh = self.to_hash
self['content-type']= self['content-type']+"; charset="+method.downcase
warning "Charset vs content-encoding confusion, trying to recover: from\n#{old_hsh.pretty_inspect}to\n#{self.to_hash.pretty_inspect}"
return str
else
debug self.to_hash
raise "Unhandled content encoding #{method}"
end
end