diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index e738f2db69..9f46caa8e8 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -573,6 +573,8 @@ def on_message_complete params.update WEBrick::HTTPUtils.parse_form_data(@body, boundary) elsif /^application\/json/.match?(@content_type) params['json'] = @body + elsif /^application\/csp-report/.match?(@content_type) + params['json'] = @body elsif /^application\/msgpack/.match?(@content_type) params['msgpack'] = @body elsif /^application\/x-ndjson/.match?(@content_type) @@ -580,7 +582,7 @@ def on_message_complete end path_info = uri.path - if (@add_query_params) + if (@add_query_params) query_params = WEBrick::HTTPUtils.parse_query(uri.query) diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index e66845520a..88d8eacdad 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -517,6 +517,28 @@ def test_application_json assert_equal_event_time time, d.events[1][1] end + def test_csp_report + d = create_driver + time = event_time("2011-01-02 13:14:15 UTC") + time_i = time.to_i + events = [ + ["tag1", time, {"a"=>1}], + ["tag2", time, {"a"=>2}], + ] + res_codes = [] + + d.run(expect_records: 2) do + events.each do |tag, t, record| + res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/csp-report; charset=utf-8"}) + res_codes << res.code + end + end + assert_equal ["200", "200"], res_codes + assert_equal events, d.events + assert_equal_event_time time, d.events[0][1] + assert_equal_event_time time, d.events[1][1] + end + def test_application_msgpack d = create_driver time = event_time("2011-01-02 13:14:15 UTC") @@ -982,7 +1004,7 @@ def test_cors_disallowed assert_equal ["403", "403"], res_codes end - def test_add_query_params + def test_add_query_params d = create_driver(config + "add_query_params true") assert_equal true, d.instance.add_query_params