Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact match for in http header #2761

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 35 additions & 3 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 Expand Up @@ -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")
Expand Down Expand Up @@ -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"]')

Expand All @@ -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"]')

Expand Down