Skip to content

Commit

Permalink
fix(http-log): add port information to the host header (#13116)
Browse files Browse the repository at this point in the history
Fix #13067
  • Loading branch information
dingjiayi authored Jun 4, 2024
1 parent 6c474d5 commit 3066f50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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

1 comment on commit 3066f50

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:3066f5032ea2bb30afa39a2ee91c93a0a85d0ce2
Artifacts available https://github.com/Kong/kong/actions/runs/9360459563

Please sign in to comment.