lib/httpx/plugins/compression.rb in httpx-0.17.0 vs lib/httpx/plugins/compression.rb in httpx-0.18.0
- old
+ new
@@ -70,10 +70,12 @@
@headers["content-length"] = @body.bytesize unless unbounded_body?
end
end
module ResponseBodyMethods
+ using ArrayExtensions
+
attr_reader :encodings
def initialize(*)
@encodings = []
@@ -88,21 +90,21 @@
@headers["content-length"].to_i
else
Float::INFINITY
end
- @_inflaters = @headers.get("content-encoding").map do |encoding|
+ @_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.compact
+ end
# this can happen if the only declared encoding is "identity"
remove_instance_variable(:@_inflaters) if @_inflaters.empty?
end
@@ -132,10 +134,10 @@
@buffer = StringIO.new("".b, File::RDWR)
@deflater = deflater
end
def each(&blk)
- return enum_for(__method__) unless block_given?
+ return enum_for(__method__) unless blk
return deflate(&blk) if @buffer.size.zero?
@buffer.rewind
@buffer.each(&blk)