[wip/proposal] fix(pdk): service.response.get_headers
behavior
#13827
+390
−114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit attempts to fix several issues in the
kong.service.response.get_headers()
module.Issues
Said method must only return response headers set by the upstream service. However, since its introcution, it is broken; in the original implementation, it added an
__index
metamethod to the full headers table (both Kong and upstream headers) to ensure a given header being indexed was found in angx.var.upstream_http_<header_name>
variable (ie, it was set by the upstream). However, it responded with the table itself, which contained the headers, so the__index
metamethod would never be called. Summarizing, since its introduction, the method has been returning both Kong and upstream headers. Tests were also broken due to a case-sensitiveness issue (implementation described above bypased the original headers table metatable, effectively breaking case-insensitiveness implemented by thengx.resp.get_headers
API).Buffered proxying, later added, introduced new logic to handle buffered headers. This logic corretly implemented the metamethod by using a so-called "proxy table"; this is an empty table to which the
__index
metamethod is added. Since it's empty,__index
is correctly invoked and ensures only upstream headers are accessible (as described by 1.). However, being empty it does not allow the headers table to be iterated on, leading to inconsistent and unexpected behavior -- a source of bug reports (e.g., Cannot iterate on headers from kong.service.response.get_headers() #11546, KAG-4866, to name two).What does it change?
Caveats
max_headers
arguably does not make sense.max_headers
, as the call tongx.resp.get_headers
includes both Kong and upstream headers and we filter out non-upstream headers after said call. The ideal solution would use a native API that reads upstream only headers directly, and has a similar interface asngx.resp.get_headers
, taking amax_headers
argument.KAG-4866