Class: FaradayMiddleware::Gzip

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/faraday_middleware/gzip.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faraday_middleware/gzip.rb', line 7

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