Skip to content

Commit

Permalink
fix to exact match
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Jan 6, 2020
1 parent c676086 commit d995892
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 32 additions & 0 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d995892

Please sign in to comment.