feat(core): support inbound and outbound Via header
Summary
According to RFC7230 and RFC9110 gateway MUST append protocol, version and host (or pseudonym) information when forwarding HTTP messages from clients to upstreams. Currently, Kong just ignores this part.
And optionally append the information when forwarding messages in the reverse direction, depending on the headers configuration. Currently, Kong blindly overrides the response Via header.
This PR will append inbound info like HTTP/1.1 kong/3.8.0, and outbound info like 1.1 kong/3.8.0 (scheme is optional).
This is scheduled for 3.8.0.
Checklist
- [x] The Pull Request has tests
- [x] A changelog file has been created under
changelog/unreleased/kongorskip-changeloglabel added on PR if changelog is unnecessary. README.md - [ ] There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE
Issue reference
Fix #FTI-5807
Will add tests to spec/02-integration/05-proxy/03-upstream_headers_spec.lua
Latest RFC: https://datatracker.ietf.org/doc/html/rfc9110#name-via
This is for 3.8.0. Please do not merge it until 3.7.0 GA.
This is for 3.8.0 as Paypal (customer candidate) may have further requirements.
Just did a rebase and waiting for CI.
A couple of comments:
- I would love to see tests added where we have
2.0as protocol version in incoming (http2/grpc) and2.0on upstream when doinggrpc_pass(not sure about1.0, should we test it too). (a real integration test) - this has long been how Kong does it, so it has kinda become a "feature", thus fixing it according to RFC may cause breakage in customers systems, e.g. those that expect these headers to only ever have single value. so just as a not, not sure if that is enough to post-pone this to 4.0 (perhaps product can answer).
- additional breakage is
proxy_set_header Via $upstream_via;, so any plugin that setsViacurrently does not work anymore as they will get overridden (again I am not sure if that is a bad thing, just pointing out)
@outsinre also things like these: https://github.com/Kong/kong/blob/master/kong/plugins/aws-lambda/handler.lua#L240-L242
Successfully created cherry-pick PR for master:
- https://github.com/kong/kong-ee/pull/9716