class Protocol::HTTP::AcceptEncoding
A middleware that sets the accept-encoding header and decodes the response according to the content-encoding header.
def call(request)
@parameter request [Protocol::HTTP::Request] The request to modify.
Set the accept-encoding header and decode the response body.
def call(request) request.headers[ACCEPT_ENCODING] = @accept_encoding response = super if body = response.body and !body.empty? and content_encoding = response.headers.delete(CONTENT_ENCODING) # We want to unwrap all encodings content_encoding.reverse_each do |name| if wrapper = @wrappers[name] body = wrapper.call(body) end end response.body = body end return response end
def initialize(delegate, wrappers = DEFAULT_WRAPPERS)
@parameter delegate [Protocol::HTTP::Middleware] The delegate middleware.
Initialize the middleware with the given delegate and wrappers.
def initialize(delegate, wrappers = DEFAULT_WRAPPERS) super(delegate) @accept_encoding = wrappers.keys.join(", ") @wrappers = wrappers end