From c676086bde9d9d89aec92cf4eb14c8eecd480ed3 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Mon, 6 Jan 2020 12:46:03 +0900 Subject: [PATCH 1/2] trim trailing space Signed-off-by: Yuta Iwama --- test/plugin/test_in_http.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index d1511b3b55..b606aff1ce 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -446,7 +446,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 +716,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 +736,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"]') From d995892b9d65b2c7a8837333949bf672cc870682 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Mon, 6 Jan 2020 12:59:47 +0900 Subject: [PATCH 2/2] fix to exact match Signed-off-by: Yuta Iwama --- lib/fluent/plugin/in_http.rb | 18 +++++++++--------- test/plugin/test_in_http.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) 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 b606aff1ce..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")