1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/net/http/test_post_io.rb
nahi 06cbdc307a * test/net/http/test_post_io.rb: parse chunked stream to avoid client
side connection error raised.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-22 02:01:34 +00:00

38 lines
1.1 KiB
Ruby

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
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))
sock.read(chunk_header.to_i(16))
# parse chunked stream to the end
assert_equal("\r\n", sock.read(2))
assert_equal("1\r\n", sock.read(3))
assert_equal("\0\r\n", sock.read(3))
assert_equal("0\r\n\r\n", sock.read(5))
ensure
sock.close
end
}
ensure
t.join if t
end
end