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

fix(http-log): add port information to the host header #13116

Merged
merged 1 commit into from
Jun 4, 2024
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
4 changes: 4 additions & 0 deletions changelog/unreleased/kong/fix-http-log-host-header.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: "**HTTP-Log**: Fix an issue where the plugin doesn't include port information in the HTTP host header when sending requests to the log server."
type: bugfix
scope: Plugin

1 change: 0 additions & 1 deletion kong/plugins/http-log/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ local function send_entries(conf, entries)
httpc:set_timeout(timeout)

local headers = {
["Host"] = host,
["Content-Type"] = content_type,
["Content-Length"] = content_length,
["Authorization"] = userinfo and "Basic " .. encode_base64(userinfo) or nil
Expand Down
34 changes: 34 additions & 0 deletions spec/03-plugins/03-http-log/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ for _, strategy in helpers.each_strategy() do
}
}

local route5 = bp.routes:insert {
hosts = { "http_host_header.test" },
service = service1
}

bp.plugins:insert {
route = { id = route5.id },
name = "http-log",
config = {
http_endpoint = "http://" .. helpers.mock_upstream_host
.. ":"
.. helpers.mock_upstream_port
.. "/post_log/http_host_header"
}
}

local route6 = bp.routes:insert {
hosts = { "https_logging_faulty.test" },
service = service2
Expand Down Expand Up @@ -535,6 +551,24 @@ for _, strategy in helpers.each_strategy() do
assert.same(vault_env_value, entries[1].log_req_headers.key2)
end)

it("http client implicitly adds Host header", function()
reset_log("http_host_header")
local res = proxy_client:get("/status/200", {
headers = {
["Host"] = "http_host_header.test"
}
})
assert.res_status(200, res)

local entries = get_log("http_host_header", 1)
local host_header
if helpers.mock_upstream_port == 80 then
host_header = helpers.mock_upstream_host
else
host_header = helpers.mock_upstream_host .. ":" .. helpers.mock_upstream_port
end
assert.same(entries[1].log_req_headers['host'] or "", host_header)
end)

it("puts changed configuration into effect immediately", function()
local admin_client = assert(helpers.admin_client())
Expand Down
Loading