summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--lib/net/http/response.rb8
-rw-r--r--test/net/http/test_httpresponse.rb53
-rw-r--r--version.h2
4 files changed, 81 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 2579992bfe..c58b1c23ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Mon Aug 17 17:38:15 2015 Kazuki Tsujimoto <kazuki@callcc.net>
+
+ * lib/net/http/response.rb (Net::HTTPResponse::Inflater#finish):
+ fix a bug that empty gzipped response body causes Zlib::BufError.
+ [ruby-core:68846] [Bug #11058]
+
+ * test/net/http/test_httpresponse.rb: tests for the above.
+
+Mon Aug 17 17:38:15 2015 Kazuki Tsujimoto <kazuki@callcc.net>
+
+ * lib/net/http/response.rb (Net::HTTPResponse#inflater):
+ fix TypeError. An exception object might be nil.
+ [ruby-core:68846] [Bug #11058]
+
+Mon Aug 17 17:38:15 2015 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * lib/net/http/response.rb (Net::HTTPResponse.each_response_header):
+ raise first exception even if inflate_body_io.finish raises error.
+ when begin block raises error, finish usually raises error too.
+
Mon Aug 17 17:16:22 2015 Aaron Patterson <tenderlove@ruby-lang.org>
* .travis.yml: update libssl before running tests.
diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb
index a36b3af36b..95d4d0ce94 100644
--- a/lib/net/http/response.rb
+++ b/lib/net/http/response.rb
@@ -260,7 +260,12 @@ class Net::HTTPResponse
begin
yield inflate_body_io
ensure
- inflate_body_io.finish
+ orig_err = $!
+ begin
+ inflate_body_io.finish
+ rescue => err
+ raise orig_err || err
+ end
end
when 'none', 'identity' then
self.delete 'content-encoding'
@@ -355,6 +360,7 @@ class Net::HTTPResponse
# Finishes the inflate stream.
def finish
+ return if @inflate.total_in == 0
@inflate.finish
end
diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb
index a9cd9f5d26..404c7ae1fa 100644
--- a/test/net/http/test_httpresponse.rb
+++ b/test/net/http/test_httpresponse.rb
@@ -237,6 +237,59 @@ EOS
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(<<EOS)
+HTTP/1.1 200 OK
+Connection: close
+Content-Encoding: deflate
+Content-Length: 0
+
+EOS
+
+ res = Net::HTTPResponse.read_new(io)
+ res.decode_content = true
+
+ body = nil
+
+ res.reading_body io, true do
+ body = res.read_body
+ end
+
+ if Net::HTTP::HAVE_ZLIB
+ assert_equal nil, res['content-encoding']
+ assert_equal '', body
+ else
+ assert_equal 'deflate', res['content-encoding']
+ assert_equal '', body
+ end
+ end
+
+ def test_read_body_content_encoding_deflate_empty_body_no_length
+ io = dummy_io(<<EOS)
+HTTP/1.1 200 OK
+Connection: close
+Content-Encoding: deflate
+
+EOS
+
+ res = Net::HTTPResponse.read_new(io)
+ res.decode_content = true
+
+ body = nil
+
+ res.reading_body io, true do
+ body = res.read_body
+ end
+
+ if Net::HTTP::HAVE_ZLIB
+ assert_equal nil, res['content-encoding']
+ assert_equal '', body
+ else
+ assert_equal 'deflate', res['content-encoding']
+ assert_equal '', body
+ end
+ end
+
def test_read_body_string
io = dummy_io(<<EOS)
HTTP/1.1 200 OK
diff --git a/version.h b/version.h
index 76851b44b9..8fe898d5ac 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.7"
#define RUBY_RELEASE_DATE "2015-08-17"
-#define RUBY_PATCHLEVEL 391
+#define RUBY_PATCHLEVEL 392
#define RUBY_RELEASE_YEAR 2015
#define RUBY_RELEASE_MONTH 8