lib/httpx/plugins/compression.rb in httpx-0.22.5 vs lib/httpx/plugins/compression.rb in httpx-0.23.0
- old
+ new
@@ -18,14 +18,11 @@
klass.plugin(:"compression/gzip")
klass.plugin(:"compression/deflate")
end
def extra_options(options)
- encodings = Module.new do
- extend Registry
- end
- options.merge(encodings: encodings)
+ options.merge(encodings: {})
end
end
module OptionsMethods
def option_compression_threshold_size(value)
@@ -34,11 +31,11 @@
bytes
end
def option_encodings(value)
- raise TypeError, ":encodings must be a registry" unless value.respond_to?(:registry)
+ raise TypeError, ":encodings must be an Hash" unless value.is_a?(Hash)
value
end
end
@@ -47,11 +44,11 @@
super
# forego compression in the Range cases
if @headers.key?("range")
@headers.delete("accept-encoding")
else
- @headers["accept-encoding"] ||= @options.encodings.registry.keys
+ @headers["accept-encoding"] ||= @options.encodings.keys
end
end
end
module RequestBodyMethods
@@ -63,11 +60,13 @@
return if threshold && !unbounded_body? && @body.bytesize < threshold
@headers.get("content-encoding").each do |encoding|
next if encoding == "identity"
- @body = Encoder.new(@body, options.encodings.registry(encoding).deflater)
+ next unless options.encodings.key?(encoding)
+
+ @body = Encoder.new(@body, options.encodings[encoding].deflater)
end
@headers["content-length"] = @body.bytesize unless unbounded_body?
end
end
@@ -93,10 +92,12 @@
end
@_inflaters = @headers.get("content-encoding").filter_map do |encoding|
next if encoding == "identity"
- inflater = @options.encodings.registry(encoding).inflater(compressed_length)
+ next unless @options.encodings.key?(encoding)
+
+ inflater = @options.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