Skip to content

Commit 00bf9d9

Browse files
committed
Improved documentation for Protocol::HTTP::AcceptEncoding.
1 parent 06baa24 commit 00bf9d9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/protocol/http/accept_encoding.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,37 @@
1010

1111
module 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

0 commit comments

Comments
 (0)