Class: HTTP::Features::AutoInflate
- Inherits:
-
HTTP::Feature
- Object
- HTTP::Feature
- HTTP::Features::AutoInflate
- Defined in:
- lib/http/features/auto_inflate.rb,
sig/http.rbs
Overview
Automatically decompresses response bodies
Constant Summary collapse
- SUPPORTED_ENCODING =
Set.new(%w[deflate gzip x-gzip]).freeze
Instance Method Summary collapse
-
#inflated_response_options(response) ⇒ Hash
private
Build options hash for an inflated response.
-
#stream_for(connection, encoding: Encoding::BINARY) ⇒ HTTP::Response::Body
Returns an inflating body stream for a connection.
-
#supported_encoding?(response) ⇒ Boolean
private
Check if the response encoding is supported.
-
#wrap_response(response) ⇒ HTTP::Response
Wraps a response with an auto-inflating body.
Methods inherited from HTTP::Feature
#around_request, #on_error, #on_request, #wrap_request
Instance Method Details
#inflated_response_options(response) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build options hash for an inflated response
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/http/features/auto_inflate.rb', line 42 def (response) { status: response.status, version: response.version, headers: response.headers, proxy_headers: response.proxy_headers, connection: response.connection, body: stream_for(response.connection, encoding: response.body.encoding), request: response.request } end |
#stream_for(connection, encoding: Encoding::BINARY) ⇒ HTTP::Response::Body
Returns an inflating body stream for a connection
33 34 35 |
# File 'lib/http/features/auto_inflate.rb', line 33 def stream_for(connection, encoding: Encoding::BINARY) Response::Body.new(Response::Inflater.new(connection), encoding: encoding) end |
#supported_encoding?(response) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the response encoding is supported
56 57 58 59 |
# File 'lib/http/features/auto_inflate.rb', line 56 def supported_encoding?(response) content_encoding = response.headers.get(Headers::CONTENT_ENCODING).first content_encoding && SUPPORTED_ENCODING.include?(content_encoding) end |
#wrap_response(response) ⇒ HTTP::Response
Wraps a response with an auto-inflating body
18 19 20 21 22 |
# File 'lib/http/features/auto_inflate.rb', line 18 def wrap_response(response) return response unless supported_encoding?(response) Response.new(**(response)) # steep:ignore end |