Closed jonhy-bigodes closed 4 years ago
Hello, thanks for reporting this. Could you please try with a more recent version of Kong?
Sure, no problem. With the latest version the bug still happens.
The problem is located at the PDK code https://github.com/Kong/kong/blob/master/kong/pdk/service.lua (line 99):
ngx.var.upstream_host = host
This _upstreamhost variable drives the "Host" header and is missing the port subcomponent. Just changing code to ngx.var.upstream_host = host .. ":" .. port
should fix it.
In the meantime, the workaround is setting the "Host" header programmatically after the _kong.service.settarget() call.
Summary
While developing a plugin that changes the upstream target host/port it was noticed that the "Host" header that is set while invoking PDK function kong.service.set_target() is not setting the port subcomponent, only the host part. This is not conforming with RFC7230, Section 5.4. When a target service uses an intermediate load balancer (eg: HAProxy) and the service uses a non-standard http/https port, the service request call fails at the load balancer level since the "Host" header is missing the port information (set by kong.service.set_target()).
Steps To Reproduce
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; } | nc -4 -l 10000 -q 1; done
)Additional Details & Logs