Sha256: a3c3471da3fb40f67b0d9e5e675b66515749a142da9fa0cb7a18a96d89161e85

Contents?: true

Size: 772 Bytes

Versions: 9

Compression:

Stored size: 772 Bytes

Contents

module Pupa
  class Processor
    module Middleware
      # A Faraday response middleware for parsing gzip responses.
      #
      # @see https://gist.github.com/romanbsd/3892387
      class Gzip < Faraday::Response::Middleware
        dependency 'zlib'

        def on_complete(env)
          encoding = env[:response_headers]['content-encoding'].to_s.downcase
          case encoding
          when 'gzip'
            env[:body] = Zlib::GzipReader.new(StringIO.new(env[:body]), encoding: 'ASCII-8BIT').read
            env[:response_headers].delete('content-encoding')
          when 'deflate'
            env[:body] = Zlib::Inflate.inflate(env[:body])
            env[:response_headers].delete('content-encoding')
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pupa-0.1.7 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.6 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.5 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.4 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.3 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.2 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.1 lib/pupa/processor/middleware/gzip.rb
pupa-0.1.0 lib/pupa/processor/middleware/gzip.rb
pupa-0.0.13 lib/pupa/processor/middleware/gzip.rb