7: def handle(ctx, options)
8: body = options[:response_body]
9: response = options[:response]
10:
11: options[:response_body] =
12: if encoding = response['Content-Encoding']
13: case encoding.downcase
14: when 'gzip'
15: Mechanize.log.debug('gunzip body') if Mechanize.log
16: if response['Content-Length'].to_i > 0 || body.length > 0
17: begin
18: Zlib::GzipReader.new(body).read
19: rescue Zlib::BufError, Zlib::GzipFile::Error
20: if Mechanize.log
21: Mechanize.log.error('Caught a Zlib::BufError')
22: end
23: body.rewind
24: body.read(10)
25: Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(body.read)
26: end
27: else
28: ''
29: end
30: when 'x-gzip'
31: body.read
32: else
33: raise 'Unsupported content encoding'
34: end
35: else
36: body.read
37: end
38: super
39: end