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.
76 77 78 |
# File 'lib/httpx/plugins/compression.rb', line 76 def encodings @encodings end |
Instance Method Details
#initialize ⇒ Object
78 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 110 |
# File 'lib/httpx/plugins/compression.rb', line 78 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" next unless .encodings.key?(encoding) inflater = .encodings[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
112 113 114 115 116 117 |
# File 'lib/httpx/plugins/compression.rb', line 112 def write(chunk) return super unless defined?(@_inflaters) && !chunk.empty? chunk = decompress(chunk) super(chunk) end |