summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 08:10:42 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 08:10:42 +0000
commitb219a56c07ad5d9fb1f6cddfb78e97eff1e89379 (patch)
treeabbc8b358cb403ce305697538fd7c47f3a485f3a /test/net
parentda1db8b454c6f8f0714d762c72815cf73efba4d8 (diff)
* 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 <drbrain@segment7.net>. * 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
Diffstat (limited to 'test/net')
-rw-r--r--test/net/http/test_http.rb81
1 files changed, 81 insertions, 0 deletions
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