[前][次][番号順一覧][スレッド一覧]

ruby-changes:39384

From: ktsj <ko1@a...>
Date: Sat, 1 Aug 2015 17:24:01 +0900 (JST)
Subject: [ruby-changes:39384] ktsj:r51465 (trunk): * lib/net/http/response.rb (Net::HTTPResponse::Inflater#finish):

ktsj	2015-08-01 17:23:32 +0900 (Sat, 01 Aug 2015)

  New Revision: 51465

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51465

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http/response.rb
    trunk/test/net/http/test_httpresponse.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51464)
+++ ChangeLog	(revision 51465)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Aug  1 17:13:15 2015  Kazuki Tsujimoto  <kazuki@c...>
+
+	* 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.
+
 Sat Aug  1 17:05:18 2015  Kazuki Tsujimoto  <kazuki@c...>
 
 	* lib/net/http/response.rb (Net::HTTPResponse#inflater):
Index: lib/net/http/response.rb
===================================================================
--- lib/net/http/response.rb	(revision 51464)
+++ lib/net/http/response.rb	(revision 51465)
@@ -359,6 +359,7 @@ class Net::HTTPResponse https://github.com/ruby/ruby/blob/trunk/lib/net/http/response.rb#L359
     # Finishes the inflate stream.
 
     def finish
+      return if @inflate.total_in == 0
       @inflate.finish
     end
 
Index: test/net/http/test_httpresponse.rb
===================================================================
--- test/net/http/test_httpresponse.rb	(revision 51464)
+++ test/net/http/test_httpresponse.rb	(revision 51465)
@@ -237,6 +237,59 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpresponse.rb#L237
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]