diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index dd493a4e36..6e706d0389 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -331,29 +331,29 @@ def on_headers_complete(headers) headers.each_pair {|k,v| @env["HTTP_#{k.gsub('-','_').upcase}"] = v case k - when /Expect/i + when /\AExpect\z/i expect = v - when /Content-Length/i + when /\AContent-Length\Z/i size = v.to_i - when /Content-Type/i + when /\AContent-Type\Z/i @content_type = v - when /Content-Encoding/i + when /\AContent-Encoding\Z/i @content_encoding = v - when /Connection/i + when /\AConnection\Z/i if v =~ /close/i @keep_alive = false elsif v =~ /Keep-alive/i @keep_alive = true end - when /Origin/i + when /\AOrigin\Z/i @origin = v - when /X-Forwarded-For/i + when /\AX-Forwarded-For\Z/i # For multiple X-Forwarded-For headers. Use first header value. v = v.first if v.is_a?(Array) @remote_addr = v.split(",").first - when /Access-Control-Request-Method/i + when /\AAccess-Control-Request-Method\Z/i @access_control_request_method = v - when /Access-Control-Request-Headers/i + when /\AAccess-Control-Request-Headers\Z/i @access_control_request_headers = v end } diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index d1511b3b55..3847f4a3c2 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -208,6 +208,38 @@ def test_json_with_add_remote_addr assert_equal_event_time time, d.events[1][1] end + def test_exact_match_for_expect + d = create_driver(CONFIG) + records = [{ "a" => 1}, { "a" => 2 }] + tag = "tag1" + res_codes = [] + + d.run(expect_records: 0, timeout: 5) do + res = post("/#{tag}", { "json" => records.to_json }, { 'Expect' => 'something' }) + res_codes << res.code + end + assert_equal ["417"], res_codes + end + + def test_exact_match_for_expect_with_other_header + d = create_driver(CONFIG) + + records = [{ "a" => 1}, { "a" => 2 }] + tag = "tag1" + res_codes = [] + + d.run(expect_records: 2, timeout: 5) do + res = post("/#{tag}", { "json" => records.to_json, 'x-envoy-expected-rq-timeout-ms' => 4 }) + res_codes << res.code + end + assert_equal ["200"], res_codes + + assert_equal "tag1", d.events[0][0] + assert_equal 1, d.events[0][2]["a"] + assert_equal "tag1", d.events[1][0] + assert_equal 2, d.events[1][2]["a"] + end + def test_multi_json_with_add_remote_addr d = create_driver(CONFIG + "add_remote_addr true") time = event_time("2011-01-02 13:14:15 UTC") @@ -446,7 +478,7 @@ def test_application_msgpack assert_equal_event_time time, d.events[0][1] assert_equal_event_time time, d.events[1][1] end - + def test_msgpack d = create_driver time = event_time("2011-01-02 13:14:15 UTC") @@ -716,7 +748,7 @@ def test_cors_allowed_wildcard_for_subdomain end end end - + def test_cors_allowed_exclude_empty_string d = create_driver(CONFIG + 'cors_allow_origins ["", "http://*.foo.com"]') @@ -736,7 +768,7 @@ def test_cors_allowed_exclude_empty_string end end end - + def test_cors_allowed_wildcard_preflight_for_subdomain d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')