kong icon indicating copy to clipboard operation
kong copied to clipboard

http-log plugin: Host header not including port

Open dingjiayi opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Kong version ($ kong version)

Kong 3.6

Current Behavior

  • use http-log plugin with config http_endpoint="http://host_name:8080/log"

  • endpoint receive request with host head: Host: host_name

Expected Behavior

endpoint receive request with host head: Host: host_name:8080

The "Host" header field in a request provides the host and port information from the target URI ...

From the RFC , we can see the Host header should include the port. If no port is included, the default port for the service requested is implied (e.g., 443 for an HTTPS URL, and 80 for an HTTP URL).

Steps To Reproduce

No response

Anything else?

No response

dingjiayi avatar May 23 '24 11:05 dingjiayi

@dingjiayi Thanks for your report. I'd like to clarify one thing.

endpoint receive request with host head: Host: host_name:8080

Do you mean the Host header as part of the Kong request log sent by the http-log plugin? Or the Host header of the request that was used to send the Kong request log?

My understanding is that you configured the http-log plugins using http_endpoint="http://host_name:8080/log", and the logging server received a logging request from this plugin, and the Host header of this request is host_name instead of host_name:8080. Am I right?

ADD-SP avatar May 27 '24 06:05 ADD-SP

@ADD-SP

My understanding is that you configured the http-log plugins using http_endpoint="http://host_name:8080/log", and the logging server received a logging request from this plugin, and the Host header of this request is host_name instead of host_name:8080. Am I right?

Right. Sorry for my unclear description.

This is caused by line 117 ["Host"] = host, as blow https://github.com/Kong/kong/blob/4e006aa85d7de34668ad40d601e275b575f0d2aa/kong/plugins/http-log/handler.lua#L116-L121

If it's confirmed to be a bug, I would be willing to submit a PR to fix it.

I think it could be resolved by directly removing the code on line 117. Just like many other HTTP client libraries, lua-resty-http automatically sets the Host header in the underlying layer when the upper-layer request doesn't have a Host header set.

dingjiayi avatar May 27 '24 07:05 dingjiayi

@ADD-SP

My understanding is that you configured the http-log plugins using http_endpoint="http://host_name:8080/log", and the logging server received a logging request from this plugin, and the Host header of this request is host_name instead of host_name:8080. Am I right?

Right. Sorry for my unclear description.

This is caused by line 117 ["Host"] = host, as blow

https://github.com/Kong/kong/blob/4e006aa85d7de34668ad40d601e275b575f0d2aa/kong/plugins/http-log/handler.lua#L116-L121

If it's confirmed to be a bug, I would be willing to submit a PR to fix it.

I think it could be resolved by directly removing the code on line 117. Just like many other HTTP client libraries, lua-resty-http automatically sets the Host header in the underlying layer when the upper-layer request doesn't have a Host header set.

I think this is a bug, PR is welcome. @dingjiayi

ADD-SP avatar May 27 '24 07:05 ADD-SP