Skip to content

in_http: replace WEBrick::HTTPUtils.parse_query with URI #4900

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
10 changes: 7 additions & 3 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ def on_message_complete
@env['REMOTE_ADDR'] = @remote_addr if @remote_addr

uri = URI.parse(@parser.request_url)
params = WEBrick::HTTPUtils.parse_query(uri.query)
params = parse_query(uri.query)

if @format_name != 'default'
params[EVENT_RECORD_PARAMETER] = @body
elsif /^application\/x-www-form-urlencoded/.match?(@content_type)
params.update WEBrick::HTTPUtils.parse_query(@body)
params.update parse_query(@body)
elsif @content_type =~ /^multipart\/form-data; boundary=(.+)/
boundary = WEBrick::HTTPUtils.dequote($1)
params.update WEBrick::HTTPUtils.parse_form_data(@body, boundary)
Expand All @@ -553,7 +553,7 @@ def on_message_complete

if (@add_query_params)

query_params = WEBrick::HTTPUtils.parse_query(uri.query)
query_params = parse_query(uri.query)

query_params.each_pair {|k,v|
params["QUERY_#{k.tr('-','_').upcase}"] = v
Expand Down Expand Up @@ -643,6 +643,10 @@ def include_cors_allow_origin

!r.nil?
end

def parse_query(query)
query.nil? ? {} : Hash[URI.decode_www_form(query, Encoding::ASCII_8BIT)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

';' separator to be ignored. Is it ok here?
(I'm not sure difference WEBrick::HTTPUtils.parse_query and URI.decode_www_form)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't notice that.

If we want to keep that specification, it would be better not to replace it by force.

WEBrick::HTTPUtils is just a util, so it might be harmless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a breaking change, but it might be acceptable for v1.19.
Should we move forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should give it some time.

We want to remove runtime dependence on WEBrick, but I don't see using WEBrick::HTTPUtils as a problem because it is just utils.
If more people are not happy with this change of specifications, then it might be better not to include this modification.

end
end
end
end