From 1996e2eb5bcee7297e4400abc4a2a6cc4b66a35c Mon Sep 17 00:00:00 2001 From: st0012 Date: Sat, 2 Apr 2022 14:33:00 +0100 Subject: [PATCH] Don't delete content-length before yielding inflate body The content-length information is still needed when evaluating the given block. Removing it will make `read_body_0` switch from `@socket.read length` to `@socket.read_all`, which can take very long and cause timeout. --- lib/net/http/response.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index cbe16ca2..bffa6b24 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -263,7 +263,6 @@ def inflater # :nodoc: case v&.downcase when 'deflate', 'gzip', 'x-gzip' then self.delete 'content-encoding' - had_content_length = self.delete 'content-length' inflate_body_io = Inflater.new(@socket) @@ -273,7 +272,7 @@ def inflater # :nodoc: ensure begin inflate_body_io.finish - if had_content_length + if self['content-length'] self['content-length'] = inflate_body_io.bytes_inflated.to_s end rescue => err