Class: Fauna::FaunaDecode

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/fauna/client.rb

Overview

Middleware for decompressing responses

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

:nodoc:



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/fauna/client.rb', line 262

def call(env)
  @app.call(env).on_complete do |response_env|
    raw_body = response_env[:body]
    response_env[:body] =
      case response_env[:response_headers]['Content-Encoding']
      when 'gzip'
        io = StringIO.new raw_body
        Zlib::GzipReader.new(io, external_encoding: Encoding::UTF_8).read
      when 'deflate'
        Zlib::Inflate.inflate raw_body
      else
        raw_body
      end
  end
end