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

in_http: Add support for HTTP GET requests #3373

Merged
merged 1 commit into from
May 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ def on_body(chunk)
RES_200_STATUS = "200 OK".freeze
RES_403_STATUS = "403 Forbidden".freeze

# Azure App Service sends GET requests for health checking purpose.
# Respond with `200 OK` to accommodate it.
def handle_get_request
return send_response_and_close(RES_200_STATUS, {}, "")
end

# Web browsers can send an OPTIONS request before performing POST
# to check if cross-origin requests are supported.
def handle_options_request
Expand Down Expand Up @@ -494,6 +500,10 @@ def handle_options_request
def on_message_complete
return if closing?

if @parser.http_method == 'GET'.freeze
return handle_get_request()
end

if @parser.http_method == 'OPTIONS'.freeze
return handle_options_request()
end
Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,15 @@ def test_cors_allowed_wildcard
end
end

def test_get_request
d = create_driver(CONFIG)

d.run do
res = get("/cors.test", {}, {})
assert_equal "200", res.code
end
end

def test_cors_preflight
d = create_driver(CONFIG + 'cors_allow_origins ["*"]')

Expand Down Expand Up @@ -985,6 +994,12 @@ def test_if_content_type_is_initialized_properly
assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
end

def get(path, params, header = {})
http = Net::HTTP.new("127.0.0.1", PORT)
req = Net::HTTP::Get.new(path, header)
ashie marked this conversation as resolved.
Show resolved Hide resolved
http.request(req)
end

def options(path, params, header = {})
http = Net::HTTP.new("127.0.0.1", PORT)
req = Net::HTTP::Options.new(path, header)
Expand Down