From b219a56c07ad5d9fb1f6cddfb78e97eff1e89379 Mon Sep 17 00:00:00 2001 From: nahi Date: Tue, 31 May 2011 08:10:42 +0000 Subject: * lib/net/http.rb, lib/net/protocol.rb: Allow to configure to wait server returning '100 continue' response befor sending HTTP request body. See NEWS for more detail. See #3622. Original patch is made by Eric Hodel . * test/net/http/test_http.rb: test it. * NEWS: Add new feature. On my env (Ubuntu 11.04 64bit), 9510 tests, 2203824 assertions, 0 failures, 0 errors, 29 skips -> 9514 tests, 2203836 assertions, 0 failures, 0 errors, 29 skips git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/net/http/test_http.rb | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'test') diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 18ca79e721..9a7a149702 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -464,3 +464,84 @@ class TestNetHTTP_v1_2_chunked < Test::Unit::TestCase } end end + +class TestNetHTTPContinue < Test::Unit::TestCase + CONFIG = { + 'host' => '127.0.0.1', + 'port' => 10081, + 'proxy_host' => nil, + 'proxy_port' => nil, + 'chunked' => true, + } + + include TestNetHTTPUtils + + def logfile + @debug = StringIO.new('') + end + + def mount_proc(&block) + @server.mount('/continue', WEBrick::HTTPServlet::ProcHandler.new(block.to_proc)) + end + + def test_expect_continue + mount_proc {|req, res| + req.continue + res.body = req.query['body'] + } + start {|http| + http.continue_timeout = 0.2 + http.request_post('/continue', 'body=BODY', 'expect' => '100-continue') {|res| + assert_equal('BODY', res.read_body) + } + } + assert_match(/Expect: 100-continue/, @debug.string) + assert_match(/HTTP\/1.1 100 continue/, @debug.string) + end + + def test_expect_continue_timeout + mount_proc {|req, res| + sleep 0.2 + req.continue # just ignored because it's '100' + res.body = req.query['body'] + } + start {|http| + http.continue_timeout = 0 + http.request_post('/continue', 'body=BODY', 'expect' => '100-continue') {|res| + assert_equal('BODY', res.read_body) + } + } + assert_match(/Expect: 100-continue/, @debug.string) + assert_match(/HTTP\/1.1 100 continue/, @debug.string) + end + + def test_expect_continue_error + mount_proc {|req, res| + res.status = 501 + res.body = req.query['body'] + } + start {|http| + http.continue_timeout = 0 + http.request_post('/continue', 'body=ERROR', 'expect' => '100-continue') {|res| + assert_equal('ERROR', res.read_body) + } + } + assert_match(/Expect: 100-continue/, @debug.string) + assert_not_match(/HTTP\/1.1 100 continue/, @debug.string) + end + + def test_expect_continue_error_while_waiting + mount_proc {|req, res| + res.status = 501 + res.body = req.query['body'] + } + start {|http| + http.continue_timeout = 0.5 + http.request_post('/continue', 'body=ERROR', 'expect' => '100-continue') {|res| + assert_equal('ERROR', res.read_body) + } + } + assert_match(/Expect: 100-continue/, @debug.string) + assert_not_match(/HTTP\/1.1 100 continue/, @debug.string) + end +end -- cgit v1.2.3