Sha256: 86e07271d67fd898117cd295be441c73f77df511018ee35f1ac09ded3b2d826e

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

module WWW
  class Mechanize
    class Chain
      class BodyDecodingHandler
        include WWW::Handler

        def handle(ctx, options)
          body = options[:response_body]
          response = options[:response]

          options[:response_body] = 
            if encoding = response['Content-Encoding']
              case encoding.downcase
              when 'gzip'
                Mechanize.log.debug('gunzip body') if Mechanize.log
                if response['Content-Length'].to_i > 0 || body.length > 0
                  begin
                    Zlib::GzipReader.new(body).read
                  rescue Zlib::BufError, Zlib::GzipFile::Error
                    if Mechanize.log
                      Mechanize.log.error('Caught a Zlib::BufError')
                    end
                    body.rewind
                    body.read(10)
                    Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(body.read)
                  end
                else
                  ''
                end
              when 'x-gzip'
                body.read
              else
                raise 'Unsupported content encoding'
              end
            else
              body.read
            end
          super
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mechanize-ntlm-0.9.1 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.0 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.1 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.3 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.4 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.2 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.8.5 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.9.1 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.9.2 lib/www/mechanize/chain/body_decoding_handler.rb
mechanize-0.9.0 lib/www/mechanize/chain/body_decoding_handler.rb