File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 10
10
11
11
module Protocol
12
12
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 .
14
14
class AcceptEncoding < Middleware
15
+ # The header used to request encodings.
15
16
ACCEPT_ENCODING = "accept-encoding" . freeze
17
+
18
+ # The header used to specify encodings.
16
19
CONTENT_ENCODING = "content-encoding" . freeze
17
20
21
+ # The default wrappers to use for decoding content.
18
22
DEFAULT_WRAPPERS = {
19
23
"gzip" => Body ::Inflate . method ( :for ) ,
20
24
21
25
# There is no point including this:
22
26
# 'identity' => ->(body){body},
23
27
}
24
28
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 )
27
35
28
36
@accept_encoding = wrappers . keys . join ( ", " )
29
37
@wrappers = wrappers
30
38
end
31
39
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.
32
44
def call ( request )
33
45
request . headers [ ACCEPT_ENCODING ] = @accept_encoding
34
46
You can’t perform that action at this time.
0 commit comments