Module: HTTPX::Plugins::Compression::ResponseBodyMethods
- Defined in:
- lib/httpx/plugins/compression.rb
Instance Attribute Summary collapse
-
#encodings ⇒ Object
readonly
Returns the value of attribute encodings.
Instance Method Summary collapse
Instance Attribute Details
#encodings ⇒ Object (readonly)
Returns the value of attribute encodings.
77 78 79 |
# File 'lib/httpx/plugins/compression.rb', line 77 def encodings @encodings end |
Instance Method Details
#initialize ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/httpx/plugins/compression.rb', line 79 def initialize(*) @encodings = [] super return unless @headers.key?("content-encoding") # remove encodings that we are able to decode @headers["content-encoding"] = @headers.get("content-encoding") - @encodings compressed_length = if @headers.key?("content-length") @headers["content-length"].to_i else Float::INFINITY end @_inflaters = @headers.get("content-encoding").filter_map do |encoding| next if encoding == "identity" inflater = @options.encodings.registry(encoding).inflater(compressed_length) # do not uncompress if there is no decoder available. In fact, we can't reliably # continue decompressing beyond that, so ignore. break unless inflater @encodings << encoding inflater end # this can happen if the only declared encoding is "identity" remove_instance_variable(:@_inflaters) if @_inflaters.empty? end |
#write(chunk) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/httpx/plugins/compression.rb', line 111 def write(chunk) return super unless defined?(@_inflaters) && !chunk.empty? chunk = decompress(chunk) super(chunk) end |