Sha256: 3b89ecb9faeb85cd1fb3bf23b7c437a5fd77426f9e53144c684dea27630a9d1a

Contents?: true

Size: 1.36 KB

Versions: 42

Compression:

Stored size: 1.36 KB

Contents

module Excon
  module Middleware
    class Decompress < Excon::Middleware::Base
      def request_call(datum)
        unless datum.has_key?(:response_block)
          key = datum[:headers].keys.detect {|k| k.to_s.casecmp('Accept-Encoding') == 0 } || 'Accept-Encoding'
          if datum[:headers][key].to_s.empty?
            datum[:headers][key] = 'deflate, gzip'
          end
        end
        @stack.request_call(datum)
      end

      def response_call(datum)
        unless datum.has_key?(:response_block)
          if key = datum[:response][:headers].keys.detect {|k| k.casecmp('Content-Encoding') == 0 }
            encodings = Utils.split_header_value(datum[:response][:headers][key])
            if encoding = encodings.last
              if encoding.casecmp('deflate') == 0
                # assume inflate omits header
                datum[:response][:body] = Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(datum[:response][:body])
                encodings.pop
              elsif encoding.casecmp('gzip') == 0 || encoding.casecmp('x-gzip') == 0
                datum[:response][:body] = Zlib::GzipReader.new(StringIO.new(datum[:response][:body])).read
                encodings.pop
              end
              datum[:response][:headers][key] = encodings.join(', ')
            end
          end
        end
        @stack.response_call(datum)
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 4 rubygems

Version Path
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/excon-0.45.4/lib/excon/middlewares/decompress.rb
framed_rails-0.2.0 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
framed_rails-0.1.7 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/excon-0.45.4/lib/excon/middlewares/decompress.rb
framed_rails-0.1.5 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
framed_rails-0.1.4 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
framed_rails-0.1.3 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
framed_rails-0.1.2 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
framed_rails-0.1.0 vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
excon-0.45.4 lib/excon/middlewares/decompress.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
excon-0.45.3 lib/excon/middlewares/decompress.rb
excon-0.45.2 lib/excon/middlewares/decompress.rb
excon-0.45.1 lib/excon/middlewares/decompress.rb
excon-0.45.0 lib/excon/middlewares/decompress.rb
excon-0.44.4 lib/excon/middlewares/decompress.rb
excon-0.44.3 lib/excon/middlewares/decompress.rb
excon-0.44.2 lib/excon/middlewares/decompress.rb
excon-0.44.1 lib/excon/middlewares/decompress.rb
excon-0.44.0 lib/excon/middlewares/decompress.rb