File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 1010
1111module Protocol
1212 module HTTP
13- # Set a valid accept-encoding header and decode the response.
13+ # A middleware that sets the accept-encoding header and decodes the response according to the content-encoding header .
1414 class AcceptEncoding < Middleware
15+ # The header used to request encodings.
1516 ACCEPT_ENCODING = "accept-encoding" . freeze
17+
18+ # The header used to specify encodings.
1619 CONTENT_ENCODING = "content-encoding" . freeze
1720
21+ # The default wrappers to use for decoding content.
1822 DEFAULT_WRAPPERS = {
1923 "gzip" => Body ::Inflate . method ( :for ) ,
2024
2125 # There is no point including this:
2226 # 'identity' => ->(body){body},
2327 }
2428
25- def initialize ( app , wrappers = DEFAULT_WRAPPERS )
26- super ( app )
29+ # Initialize the middleware with the given delegate and wrappers.
30+ #
31+ # @parameter delegate [Protocol::HTTP::Middleware] The delegate middleware.
32+ # @parameter wrappers [Hash] A hash of encoding names to wrapper functions.
33+ def initialize ( delegate , wrappers = DEFAULT_WRAPPERS )
34+ super ( delegate )
2735
2836 @accept_encoding = wrappers . keys . join ( ", " )
2937 @wrappers = wrappers
3038 end
3139
40+ # Set the accept-encoding header and decode the response body.
41+ #
42+ # @parameter request [Protocol::HTTP::Request] The request to modify.
43+ # @returns [Protocol::HTTP::Response] The response.
3244 def call ( request )
3345 request . headers [ ACCEPT_ENCODING ] = @accept_encoding
3446
You can’t perform that action at this time.
0 commit comments