Skip to content

Commit a5ffcda

Browse files
committed
merge revision(s) 46681,51464,51465: [Backport ruby#11058]
* 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. * lib/net/http/response.rb (Net::HTTPResponse#inflater): fix TypeError. An exception object might be nil. [ruby-core:68846] [Bug ruby#11058] * lib/net/http/response.rb (Net::HTTPResponse::Inflater#finish): fix a bug that empty gzipped response body causes Zlib::BufError. [ruby-core:68846] [Bug ruby#11058] * test/net/http/test_httpresponse.rb: tests for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent d3cd7b4 commit a5ffcda

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Mon Aug 17 17:38:15 2015 Kazuki Tsujimoto <[email protected]>
2+
3+
* lib/net/http/response.rb (Net::HTTPResponse::Inflater#finish):
4+
fix a bug that empty gzipped response body causes Zlib::BufError.
5+
[ruby-core:68846] [Bug #11058]
6+
7+
* test/net/http/test_httpresponse.rb: tests for the above.
8+
9+
Mon Aug 17 17:38:15 2015 Kazuki Tsujimoto <[email protected]>
10+
11+
* lib/net/http/response.rb (Net::HTTPResponse#inflater):
12+
fix TypeError. An exception object might be nil.
13+
[ruby-core:68846] [Bug #11058]
14+
15+
Mon Aug 17 17:38:15 2015 NARUSE, Yui <[email protected]>
16+
17+
* lib/net/http/response.rb (Net::HTTPResponse.each_response_header):
18+
raise first exception even if inflate_body_io.finish raises error.
19+
when begin block raises error, finish usually raises error too.
20+
121
Mon Aug 17 17:16:22 2015 Aaron Patterson <[email protected]>
222

323
* .travis.yml: update libssl before running tests.

lib/net/http/response.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ def inflater # :nodoc:
260260
begin
261261
yield inflate_body_io
262262
ensure
263-
inflate_body_io.finish
263+
orig_err = $!
264+
begin
265+
inflate_body_io.finish
266+
rescue => err
267+
raise orig_err || err
268+
end
264269
end
265270
when 'none', 'identity' then
266271
self.delete 'content-encoding'
@@ -355,6 +360,7 @@ def initialize socket
355360
# Finishes the inflate stream.
356361

357362
def finish
363+
return if @inflate.total_in == 0
358364
@inflate.finish
359365
end
360366

test/net/http/test_httpresponse.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,59 @@ def test_read_body_content_encoding_deflate_content_range
237237
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03", body
238238
end
239239

240+
def test_read_body_content_encoding_deflate_empty_body
241+
io = dummy_io(<<EOS)
242+
HTTP/1.1 200 OK
243+
Connection: close
244+
Content-Encoding: deflate
245+
Content-Length: 0
246+
247+
EOS
248+
249+
res = Net::HTTPResponse.read_new(io)
250+
res.decode_content = true
251+
252+
body = nil
253+
254+
res.reading_body io, true do
255+
body = res.read_body
256+
end
257+
258+
if Net::HTTP::HAVE_ZLIB
259+
assert_equal nil, res['content-encoding']
260+
assert_equal '', body
261+
else
262+
assert_equal 'deflate', res['content-encoding']
263+
assert_equal '', body
264+
end
265+
end
266+
267+
def test_read_body_content_encoding_deflate_empty_body_no_length
268+
io = dummy_io(<<EOS)
269+
HTTP/1.1 200 OK
270+
Connection: close
271+
Content-Encoding: deflate
272+
273+
EOS
274+
275+
res = Net::HTTPResponse.read_new(io)
276+
res.decode_content = true
277+
278+
body = nil
279+
280+
res.reading_body io, true do
281+
body = res.read_body
282+
end
283+
284+
if Net::HTTP::HAVE_ZLIB
285+
assert_equal nil, res['content-encoding']
286+
assert_equal '', body
287+
else
288+
assert_equal 'deflate', res['content-encoding']
289+
assert_equal '', body
290+
end
291+
end
292+
240293
def test_read_body_string
241294
io = dummy_io(<<EOS)
242295
HTTP/1.1 200 OK

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.7"
22
#define RUBY_RELEASE_DATE "2015-08-17"
3-
#define RUBY_PATCHLEVEL 391
3+
#define RUBY_PATCHLEVEL 392
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 8

0 commit comments

Comments
 (0)