diff --git a/lib/fluent/plugin_helper/http_server.rb b/lib/fluent/plugin_helper/http_server.rb index 3ca9be5405..96de327774 100644 --- a/lib/fluent/plugin_helper/http_server.rb +++ b/lib/fluent/plugin_helper/http_server.rb @@ -46,6 +46,11 @@ def initialize(*) @_http_server = nil end + def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) + logger.warn('this method is deprecated. Use #http_server_create_http_server instead') + http_server_create_http_server(title, addr: addr, port: port, logger: logger, default_app: default_app, proto: proto, tls_opts: tls_opts, &block) + end + # @param title [Symbol] the thread name. this value should be unique. # @param addr [String] Listen address # @param port [String] Listen port @@ -53,7 +58,7 @@ def initialize(*) # @param default_app [Object] This method must have #call. # @param proto [Symbol] :tls or :tcp # @param tls_opts [Hash] options for TLS. - def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) + def http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) unless block_given? raise ArgumentError, 'BUG: callback not specified' end diff --git a/test/plugin_helper/test_http_server_helper.rb b/test/plugin_helper/test_http_server_helper.rb index fc15b14300..40c5e9c7b8 100644 --- a/test/plugin_helper/test_http_server_helper.rb +++ b/test/plugin_helper/test_http_server_helper.rb @@ -179,7 +179,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr sub_test_case 'Create a HTTP server' do test 'monunt given path' do on_driver do |driver| - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] } s.post('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello post'] } s.head('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello head'] } @@ -214,7 +214,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr test 'when path does not start with `/` or ends with `/`' do on_driver do |driver| - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| s.get('example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] } s.get('/example/hello2/') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] } end @@ -229,7 +229,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr test 'when error raised' do on_driver do |driver| - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| s.get('/example/hello') { raise 'error!' } end @@ -240,7 +240,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr test 'when path is not found' do on_driver do |driver| - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] } end @@ -251,7 +251,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr test 'params and body' do on_driver do |driver| - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s| s.get('/example/hello') do |req| assert_equal(req.query_string, nil) assert_equal(req.body, nil) @@ -390,7 +390,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr end stub(Fluent::PluginHelper::HttpServer::Server).new(anything) { server } - driver.create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do + driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do # nothing end driver.stop