Skip to content

http_server: add an accessor to read request header #4903

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

Merged
merged 2 commits into from
Apr 11, 2025
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
5 changes: 5 additions & 0 deletions lib/fluent/plugin_helper/http_server/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

require 'cgi'
require 'async/http/protocol'
require 'fluent/plugin_helper/http_server/methods'

Expand All @@ -29,6 +30,10 @@ def initialize(request)
@path, @query_string = path.split('?', 2)
end

def headers
@request.headers
end

def query
@query_string && CGI.parse(@query_string)
end
Expand Down
18 changes: 18 additions & 0 deletions test/plugin_helper/http_server/test_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative '../../helper'
require 'flexmock/test_unit'
require 'fluent/plugin_helper/http_server/request'

class HttpHelperRequestTest < Test::Unit::TestCase
def test_request
headers = Protocol::HTTP::Headers.new({ 'Content-Type' => 'text/html', 'Content-Encoding' => 'gzip' })
req = flexmock('request', path: '/path?foo=42', headers: headers)

request = Fluent::PluginHelper::HttpServer::Request.new(req)

assert_equal('/path', request.path)
assert_equal('foo=42', request.query_string)
assert_equal({'foo'=>['42']}, request.query)
assert_equal('text/html', request.headers['content-type'])
assert_equal(['gzip'], request.headers['content-encoding'])
end
end
Loading