diff options
Diffstat (limited to 'test/net/http/test_http.rb')
-rw-r--r-- | test/net/http/test_http.rb | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 0508645ac5..a49cc87e8d 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -126,10 +126,10 @@ class TestNetHTTP < Test::Unit::TestCase def test_proxy_address_no_proxy TestNetHTTPUtils.clean_http_proxy_env do - http = Net::HTTP.new 'hostname.example', nil, 'proxy.example', nil, nil, nil, 'example' + http = Net::HTTP.new 'hostname.example', nil, 'proxy.com', nil, nil, nil, 'example' assert_nil http.proxy_address - http = Net::HTTP.new '10.224.1.1', nil, 'proxy.example', nil, nil, nil, 'example,10.224.0.0/22' + http = Net::HTTP.new '10.224.1.1', nil, 'proxy.com', nil, nil, nil, 'example,10.224.0.0/22' assert_nil http.proxy_address end end @@ -254,6 +254,18 @@ class TestNetHTTP < Test::Unit::TestCase end end + def test_default_configuration + Net::HTTP.default_configuration = { open_timeout: 5 } + http = Net::HTTP.new 'hostname.example' + assert_equal 5, http.open_timeout + assert_equal 60, http.read_timeout + + http.open_timeout = 10 + assert_equal 10, http.open_timeout + ensure + Net::HTTP.default_configuration = nil + end + end module TestNetHTTP_version_1_1_methods @@ -442,7 +454,11 @@ module TestNetHTTP_version_1_1_methods def test_post start {|http| _test_post__base http + } + start {|http| _test_post__file http + } + start {|http| _test_post__no_data http } end @@ -629,10 +645,12 @@ module TestNetHTTP_version_1_2_methods # _test_request__range http # WEBrick does not support Range: header. _test_request__HEAD http _test_request__POST http - _test_request__stream_body http _test_request__uri http _test_request__uri_host http } + start {|http| + _test_request__stream_body http + } end def _test_request__GET(http) @@ -843,7 +861,13 @@ Content-Type: application/octet-stream __EOM__ start {|http| _test_set_form_urlencoded(http, data.reject{|k,v|!v.is_a?(String)}) + } + start {|http| + @server.mount('/', lambda {|req, res| res.body = req.body }) _test_set_form_multipart(http, false, data, expected) + } + start {|http| + @server.mount('/', lambda {|req, res| res.body = req.body }) _test_set_form_multipart(http, true, data, expected) } } @@ -887,6 +911,7 @@ __EOM__ expected.sub!(/<filename>/, filename) expected.sub!(/<data>/, $test_net_http_data) start {|http| + @server.mount('/', lambda {|req, res| res.body = req.body }) data.each{|k,v|v.rewind rescue nil} req = Net::HTTP::Post.new('/') req.set_form(data, 'multipart/form-data') @@ -902,10 +927,11 @@ __EOM__ header) assert_equal(expected, body) - data.each{|k,v|v.rewind rescue nil} - req['Transfer-Encoding'] = 'chunked' - res = http.request req - #assert_equal(expected, res.body) + # TODO: test with chunked + # data.each{|k,v|v.rewind rescue nil} + # req['Transfer-Encoding'] = 'chunked' + # res = http.request req + # assert_equal(expected, res.body) } } end @@ -984,7 +1010,7 @@ class TestNetHTTPContinue < Test::Unit::TestCase end def mount_proc(&block) - @server.mount('/continue', WEBrick::HTTPServlet::ProcHandler.new(block.to_proc)) + @server.mount('/continue', block.to_proc) end def test_expect_continue @@ -1039,7 +1065,7 @@ class TestNetHTTPContinue < Test::Unit::TestCase def test_expect_continue_error_before_body @log_tester = nil mount_proc {|req, res| - raise WEBrick::HTTPStatus::Forbidden + raise TestNetHTTPUtils::Forbidden } start {|http| uheader = {'content-type' => 'application/x-www-form-urlencoded', 'content-length' => '5', 'expect' => '100-continue'} @@ -1084,7 +1110,7 @@ class TestNetHTTPSwitchingProtocols < Test::Unit::TestCase end def mount_proc(&block) - @server.mount('/continue', WEBrick::HTTPServlet::ProcHandler.new(block.to_proc)) + @server.mount('/continue', block.to_proc) end def test_info @@ -1159,11 +1185,11 @@ class TestNetHTTPKeepAlive < Test::Unit::TestCase end def test_keep_alive_reset_on_new_connection - # Using WEBrick's debug log output on accepting connection: + # Using debug log output on accepting connection: # # "[2021-04-29 20:36:46] DEBUG accept: 127.0.0.1:50674\n" @log_tester = nil - @server.logger.level = WEBrick::BasicLog::DEBUG + @logger_level = :debug start {|http| res = http.get('/') @@ -1234,6 +1260,16 @@ class TestNetHTTPKeepAlive < Test::Unit::TestCase } end + def test_http_retry_failed_with_block + start {|http| + http.max_retries = 10 + called = 0 + assert_raise(Errno::ECONNRESET){ http.get('/'){called += 1; raise Errno::ECONNRESET} } + assert_equal 1, called + } + @log_tester = nil + end + def test_keep_alive_server_close def @server.run(sock) sock.close |