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

Semantic Status Code - modify on_request response from 200 to 204 in plugin/in_http #2640

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def on_request(path_info, params)
if @respond_with_empty_img
return ["200 OK", {'Content-Type'=>'image/gif; charset=utf-8'}, EMPTY_GIF_IMAGE]
else
return ["200 OK", {'Content-Type'=>'text/plain'}, ""]
return ["204 No Content", {}]
end
end

Expand Down Expand Up @@ -219,7 +219,7 @@ def on_request(path_info, params)
if @respond_with_empty_img
return ["200 OK", {'Content-Type'=>'image/gif; charset=utf-8'}, EMPTY_GIF_IMAGE]
else
return ["200 OK", {'Content-Type'=>'text/plain'}, ""]
return ["204 No Content", {}]
end
end

Expand Down
30 changes: 28 additions & 2 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ def test_with_csv
assert_equal_event_time time, d.events[1][1]
end

def test_resonse_with_empty_img
d = create_driver(CONFIG + "respond_with_empty_img true")
def test_response_with_empty_img
d = create_driver(CONFIG)
assert_equal true, d.instance.respond_with_empty_img

time = event_time("2011-01-02 13:14:15 UTC")
Expand All @@ -577,6 +577,32 @@ def test_resonse_with_empty_img
assert_equal_event_time time, d.events[1][1]
end

def test_response_without_empty_img
d = create_driver(CONFIG + "respond_with_empty_img false")
assert_equal false, d.instance.respond_with_empty_img

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 = []
res_bodies = []

d.run do
events.each do |tag, _t, record|
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
res_codes << res.code
end
end
assert_equal ["204", "204"], res_codes
assert_equal [], res_bodies
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_cors_allowed
d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
assert_equal ["http://foo.com"], d.instance.cors_allow_origins
Expand Down