Skip to content

Commit

Permalink
Fix FrozenError in http_server plugin helper
Browse files Browse the repository at this point in the history
This patch will be able to handle frozen strings as paths to mount in http server.

Signed-off-by: Watson <[email protected]>
  • Loading branch information
Watson1978 committed Aug 16, 2024
1 parent a6978e5 commit 0e2e985
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 0e2e985

Please sign in to comment.