summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-20 14:54:18 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-20 14:54:18 +0000
commit471ad3039c15e3cbb1bf9e35cc6cae0aa65acd9e (patch)
tree3f75bf9d74505f3a0fe42588096293fd1e3f76aa
parent639623ad489bc91a1240ce9c646d66f636fb52c1 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--lib/net/http.rb6
-rw-r--r--test/net/http/test_post_io.rb32
3 files changed, 45 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d75407f24..ce2e8ea5bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sun Dec 20 23:43:46 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+
+ * 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@marc-andre.ca>
* lib/set.rb (initialize): Add check that argument is enumerable
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 10ec95018a..5a794e6d9f 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -1467,6 +1467,8 @@ module Net #:nodoc:
include HTTPHeader
+ BUFSIZE = 16*1024
+
def initialize(m, reqbody, resbody, path, initheader = nil)
@method = m
@request_has_body = reqbody
@@ -1552,12 +1554,12 @@ module Net #:nodoc:
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
diff --git a/test/net/http/test_post_io.rb b/test/net/http/test_post_io.rb
new file mode 100644
index 0000000000..c4093f9347
--- /dev/null
+++ b/test/net/http/test_post_io.rb
@@ -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