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

ruby-changes:16232

From: wyhaines <ko1@a...>
Date: Tue, 8 Jun 2010 04:01:10 +0900 (JST)
Subject: [ruby-changes:16232] Ruby:r28198 (ruby_1_8_6): lib/net/http.rb: Backport #1284 ; Change Net:HTTP to use a block size of 16k instead of 1k when streaming or chunking POST bodies.

wyhaines	2010-06-08 04:00:48 +0900 (Tue, 08 Jun 2010)

  New Revision: 28198

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

  Log:
    lib/net/http.rb: Backport #1284 [ruby-core:22874]; Change Net:HTTP to use a block size of 16k instead of 1k when streaming or chunking POST bodies.
    test/net/http/test_post_io.rb: Backport #1284 [ruby-core:22874]; A test to go with the above change.

  Added files:
    branches/ruby_1_8_6/test/net/http/test_post_io.rb
  Modified files:
    branches/ruby_1_8_6/ChangeLog
    branches/ruby_1_8_6/lib/net/http.rb
    branches/ruby_1_8_6/version.h

Index: ruby_1_8_6/ChangeLog
===================================================================
--- ruby_1_8_6/ChangeLog	(revision 28197)
+++ ruby_1_8_6/ChangeLog	(revision 28198)
@@ -1,3 +1,8 @@
+Tue Jun 9 3:20:00 2010 Kirk Haines <khaines@r...>
+
+	* lib/net/http.rb: Backport #1284 [ruby-core:22874]; Change Net:HTTP to use a block size of 16k instead of 1k when streaming or chunking POST bodies.
+	* test/net/http/test_post_io.rb: Backport #1284 [ruby-core:22874]; A test to go with the above change.
+
 Fri Jun 4 5:57:00 2010 Kirk Haines <khaines@r...>
 
 	* util.c: Backport #2392 [ruby-core:26868]; backport of r23353 which suppresses a strict-aliasing warning in gcc-4.4.x -O2.
Index: ruby_1_8_6/version.h
===================================================================
--- ruby_1_8_6/version.h	(revision 28197)
+++ ruby_1_8_6/version.h	(revision 28198)
@@ -1,15 +1,15 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2010-06-04"
+#define RUBY_RELEASE_DATE "2010-06-08"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20100604
-#define RUBY_PATCHLEVEL 404
+#define RUBY_RELEASE_CODE 20100608
+#define RUBY_PATCHLEVEL 405
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2010
 #define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 4
+#define RUBY_RELEASE_DAY 8
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8_6/lib/net/http.rb
===================================================================
--- ruby_1_8_6/lib/net/http.rb	(revision 28197)
+++ ruby_1_8_6/lib/net/http.rb	(revision 28198)
@@ -1463,6 +1463,8 @@
 
     include HTTPHeader
 
+    BUFSIZE = 16*1024
+
     def initialize(m, reqbody, resbody, path, initheader = nil)
       @method = m
       @request_has_body = reqbody
@@ -1548,12 +1550,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_6/test/net/http/test_post_io.rb
===================================================================
--- ruby_1_8_6/test/net/http/test_post_io.rb	(revision 0)
+++ ruby_1_8_6/test/net/http/test_post_io.rb	(revision 28198)
@@ -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/

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