@@ -12,19 +12,30 @@ module Protocol
1212 module HTTP
1313 # Encode a response according the the request's acceptable encodings.
1414 class ContentEncoding < Middleware
15+ # The default wrappers to use for encoding content.
1516 DEFAULT_WRAPPERS = {
1617 "gzip" => Body ::Deflate . method ( :for )
1718 }
1819
20+ # The default content types to apply encoding to.
1921 DEFAULT_CONTENT_TYPES = %r{^(text/.*?)|(.*?/json)|(.*?/javascript)$}
2022
21- def initialize ( app , content_types = DEFAULT_CONTENT_TYPES , wrappers = DEFAULT_WRAPPERS )
22- super ( app )
23+ # Initialize the content encoding middleware.
24+ #
25+ # @parameter delegate [Middleware] The next middleware in the chain.
26+ # @parameter content_types [Regexp] The content types to apply encoding to.
27+ # @parameter wrappers [Hash] The encoding wrappers to use.
28+ def initialize ( delegate , content_types = DEFAULT_CONTENT_TYPES , wrappers = DEFAULT_WRAPPERS )
29+ super ( delegate )
2330
2431 @content_types = content_types
2532 @wrappers = wrappers
2633 end
2734
35+ # Encode the response body according to the request's acceptable encodings.
36+ #
37+ # @parameter request [Request] The request.
38+ # @returns [Response] The response.
2839 def call ( request )
2940 response = super
3041
@@ -40,7 +51,6 @@ def call(request)
4051
4152 # TODO use http-accept and sort by priority
4253 if !response . body . empty? and accept_encoding = request . headers [ "accept-encoding" ]
43-
4454 if content_type = response . headers [ "content-type" ] and @content_types =~ content_type
4555 body = response . body
4656
0 commit comments