class Protocol::HTTP::AcceptEncoding

Set a valid accept-encoding header and decode the response.

Constants

ACCEPT_ENCODING
CONTENT_ENCODING
DEFAULT_WRAPPERS

Public Class Methods

new(app, wrappers = DEFAULT_WRAPPERS) click to toggle source
Calls superclass method
# File lib/protocol/http/accept_encoding.rb, line 40
def initialize(app, wrappers = DEFAULT_WRAPPERS)
        super(app)
        
        @accept_encoding = wrappers.keys.join(', ')
        @wrappers = wrappers
end

Public Instance Methods

call(request) click to toggle source
Calls superclass method
# File lib/protocol/http/accept_encoding.rb, line 47
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