Skip to content

Commit

Permalink
Merge pull request #3373 from fujimotos/sf/in-http-get
Browse files Browse the repository at this point in the history
in_http: Add support for HTTP GET requests
  • Loading branch information
ashie committed May 14, 2021
2 parents e2e51d1 + ed4719f commit 5bd3346
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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)
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

0 comments on commit 5bd3346

Please sign in to comment.