Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FrozenError in http_server plugin helper #4598

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/plugin_helper/http_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def stop
HttpServer::Methods::ALL.map { |e| e.downcase.to_sym }.each do |name|
define_method(name) do |path, app = nil, &block|
unless path.end_with?('/')
path << '/'
path += '/'
end

if (block && app) || (!block && !app)
Expand Down
13 changes: 12 additions & 1 deletion test/plugin_helper/test_http_server_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr
end

sub_test_case 'Create a HTTP server' do
test 'monunt given path' do
test 'mount given path' do
on_driver do |driver|
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'] }
Expand All @@ -179,6 +179,17 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr
end
end

test 'mount frozen path' do
on_driver do |driver|
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'.freeze) { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
end

resp = get("http://127.0.0.1:#{@port}/example/hello/")
assert_equal('200', resp.code)
end
end

test 'when path does not start with `/` or ends with `/`' do
on_driver do |driver|
driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
Expand Down