Skip to content

Commit 6ce90f9

Browse files
authored
in_http: replace WEBrick::HTTPUtils.parse_query with URI (#4900)
**Which issue(s) this PR fixes**: * Partially Fixes #4648 **What this PR does / why we need it**: Replace `WEBrick::HTTPUtils.parse_query` with `URI.decode_www_form` in `in_http`. WEBrick is no longer recommended for production use. `WEBrick::HTTPUtils` is just a util, so it might be harmless. However, it would be happy to reduce dependence if possible. This changes some specifications unintentionally. At least, this makes us unable to use `;` delimitter. We need to consider whether this breaking change is acceptable or not. **Docs Changes**: Not needed. **Release Note**: The same as the title. Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
1 parent d4fd43b commit 6ce90f9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/fluent/plugin/in_http.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ def on_message_complete
531531
@env['REMOTE_ADDR'] = @remote_addr if @remote_addr
532532

533533
uri = URI.parse(@parser.request_url)
534-
params = WEBrick::HTTPUtils.parse_query(uri.query)
534+
params = parse_query(uri.query)
535535

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

554554
if (@add_query_params)
555555

556-
query_params = WEBrick::HTTPUtils.parse_query(uri.query)
556+
query_params = parse_query(uri.query)
557557

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

644644
!r.nil?
645645
end
646+
647+
def parse_query(query)
648+
query.nil? ? {} : Hash[URI.decode_www_form(query, Encoding::ASCII_8BIT)]
649+
end
646650
end
647651
end
648652
end

0 commit comments

Comments
 (0)