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

ruby-changes:14306

From: nahi <ko1@a...>
Date: Sun, 20 Dec 2009 23:54:36 +0900 (JST)
Subject: [ruby-changes:14306] Ruby:r26131 (ruby_1_8): * lib/net/http.rb (HTTPGenericRequest#send_request_with_body_stream):

nahi	2009-12-20 23:54:18 +0900 (Sun, 20 Dec 2009)

  New Revision: 26131

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

  Log:
    * lib/net/http.rb (HTTPGenericRequest#send_request_with_body_stream):
              increased encoding chunk size for POST request with body_stream
              (1K -> 16K). patched by Brian Candler. #1284.
    
            * test/net/http/test_post_io.rb: added for the patch. It's good if a
              patch comes with a test.

  Added files:
    branches/ruby_1_8/test/net/http/test_post_io.rb
  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/net/http.rb

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 26130)
+++ ruby_1_8/ChangeLog	(revision 26131)
@@ -1,3 +1,12 @@
+Sun Dec 20 23:43:46 2009  NAKAMURA, Hiroshi  <nahi@r...>
+
+	* lib/net/http.rb (HTTPGenericRequest#send_request_with_body_stream):
+	  increased encoding chunk size for POST request with body_stream
+	  (1K -> 16K). patched by Brian Candler. #1284.
+
+	* test/net/http/test_post_io.rb: added for the patch. It's good if a
+	  patch comes with a test.
+
 Sat Dec 19 09:31:25 2009  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/set.rb (initialize): Add check that argument is enumerable
Index: ruby_1_8/lib/net/http.rb
===================================================================
--- ruby_1_8/lib/net/http.rb	(revision 26130)
+++ ruby_1_8/lib/net/http.rb	(revision 26131)
@@ -1467,6 +1467,8 @@
 
     include HTTPHeader
 
+    BUFSIZE = 16*1024
+
     def initialize(m, reqbody, resbody, path, initheader = nil)
       @method = m
       @request_has_body = reqbody
@@ -1552,12 +1554,12 @@
       supply_default_content_type
       write_header sock, ver, path
       if chunked?
-        while s = f.read(1024)
+        while s = f.read(BUFSIZE)
           sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
         end
         sock.write "0\r\n\r\n"
       else
-        while s = f.read(1024)
+        while s = f.read(BUFSIZE)
           sock.write s
         end
       end
Index: ruby_1_8/test/net/http/test_post_io.rb
===================================================================
--- ruby_1_8/test/net/http/test_post_io.rb	(revision 0)
+++ ruby_1_8/test/net/http/test_post_io.rb	(revision 26131)
@@ -0,0 +1,32 @@
+require 'test/unit'
+require 'net/http'
+require 'stringio'
+
+class HTTPPostIOTest < Test::Unit::TestCase
+  def test_post_io_chunk_size
+    t = nil
+    TCPServer.open("127.0.0.1", 0) {|serv|
+      _, port, _, _ = serv.addr
+      t = Thread.new {
+        begin
+          req = Net::HTTP::Post.new("/test.cgi")
+          req['Transfer-Encoding'] = 'chunked'
+          req.body_stream = StringIO.new("\0" * (16 * 1024 + 1))
+          http = Net::HTTP.new("127.0.0.1", port)
+          res = http.start { |http| http.request(req) }
+        rescue EOFError, Errno::EPIPE
+        end
+      }
+      sock = serv.accept
+      begin
+        assert_match(/chunked/, sock.gets("\r\n\r\n"))
+        chunk_header = sock.gets.chomp
+        assert_equal(16 * 1024, chunk_header.to_i(16))
+      ensure
+        sock.close
+      end
+    }
+  ensure
+    t.join if t
+  end
+end

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

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