lib/httpx/plugins/grpc/grpc_encoding.rb in httpx-1.1.3 vs lib/httpx/plugins/grpc/grpc_encoding.rb in httpx-1.1.4
- old
+ new
@@ -34,11 +34,10 @@
end
end
class Inflater
def initialize(response)
- @encodings = response.headers.get("grpc-encoding")
@response = response
end
def call(message, &blk)
data = "".b
@@ -47,11 +46,11 @@
compressed, size = message.unpack("CL>")
encoded_data = message.byteslice(5..size + 5 - 1)
if compressed == 1
- @encodings.reverse_each do |encoding|
+ grpc_encodings.reverse_each do |encoding|
decoder = @response.body.class.initialize_inflater_by_encoding(encoding, @response, bytesize: encoded_data.bytesize)
encoded_data = decoder.call(encoded_data)
blk.call(encoded_data) if blk
@@ -65,9 +64,15 @@
message = message.byteslice((size + 5)..-1)
end
data
+ end
+
+ private
+
+ def grpc_encodings
+ @grpc_encodings ||= @response.headers.get("grpc-encoding")
end
end
def self.encode(*args, **kwargs)
Deflater.new(*args, **kwargs)