lib/async/http/accept_encoding.rb in async-http-0.35.1 vs lib/async/http/accept_encoding.rb in async-http-0.36.0

- old
+ new

@@ -25,26 +25,30 @@ module Async module HTTP # Set a valid accept-encoding header and decode the response. class AcceptEncoding < Middleware + ACCEPT_ENCODING = 'accept-encoding'.freeze + CONTENT_ENCODING = 'content-encoding'.freeze + DEFAULT_WRAPPERS = { - 'gzip' => Body::Inflate.method(:for) + 'gzip' => Body::Inflate.method(:for), + 'identity' => ->(body){body}, } def initialize(app, wrappers = DEFAULT_WRAPPERS) super(app) @accept_encoding = wrappers.keys.join(', ') @wrappers = wrappers end def call(request) - request.headers['accept-encoding'] = @accept_encoding + request.headers[ACCEPT_ENCODING] = @accept_encoding response = super - if !response.body.empty? and content_encoding = response.headers['content-encoding'] + if !response.body.empty? and content_encoding = response.headers.delete(CONTENT_ENCODING) body = response.body # We want to unwrap all encodings content_encoding.reverse_each do |name| if wrapper = @wrappers[name]