From df3123d1d7b9a0a0078ce5c89bff0aeb9a1a2935 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sat, 11 Apr 2015 17:15:09 +0900 Subject: [PATCH 2/2] * lib/net/http/response.rb (Net::HTTPResponse::Inflater): fix bug that empty gzipped response body causes Zlib::BufError. * test/net/http/test_httpresponse.rb: tests for the above. --- lib/net/http/response.rb | 3 +++ test/net/http/test_httpresponse.rb | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index 57661ca..b19f184 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -352,12 +352,14 @@ def initialize socket @socket = socket # zlib with automatic gzip detection @inflate = Zlib::Inflate.new(32 + Zlib::MAX_WBITS) + @bytes_read = 0 end ## # Finishes the inflate stream. def finish + return if @bytes_read == 0 @inflate.finish end @@ -374,6 +376,7 @@ def inflate_adapter(dest) dest.force_encoding(Encoding::ASCII_8BIT) end block = proc do |compressed_chunk| + @bytes_read += compressed_chunk.bytesize @inflate.inflate(compressed_chunk) do |chunk| dest << chunk end diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb index 0193a15..162f4a0 100644 --- a/test/net/http/test_httpresponse.rb +++ b/test/net/http/test_httpresponse.rb @@ -209,6 +209,59 @@ def test_read_body_content_encoding_deflate_content_range assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03", body end + def test_read_body_content_encoding_deflate_empty_body + io = dummy_io(<