Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(var): patch set_header #97

Merged
merged 3 commits into from
Dec 18, 2024
Merged

fix(var): patch set_header #97

merged 3 commits into from
Dec 18, 2024

Conversation

tzssangglass
Copy link
Member

@tzssangglass tzssangglass commented Dec 11, 2024

patch the req.set_header function to invalidate the relevant variable_index entry for the modified header. Specifically, after normalizing the header name, the corresponding variable_index entry is set to nil. This ensures that subsequent accesses to ngx.var.http_* variables will bypass the cached index and fetch the updated header value.

same fix way as: #59

Fix: KAG-5963
Fix: FTI-6406

patch the `req.set_header` function to invalidate the relevant `variable_index` entry for the modified header.
Specifically, after normalizing the header name, the corresponding `variable_index` entry is set to `nil`.
This ensures that subsequent accesses to `ngx.var.http_*` variables will bypass the cached index and fetch
the updated header value.

same fix way as: #59

Fix: [KAG-5963](https://konghq.atlassian.net/browse/KAG-5963)
Signed-off-by: tzssangglass <[email protected]>
local orig_set_header = req.set_header

req.set_header = function(...)
local normalized_header = replace_dashes_lower(...)
Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps I need to unpack the data structure(…) and retrieve the first element; this should be clear.

Copy link
Member

@samugi samugi Dec 13, 2024

Choose a reason for hiding this comment

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

right, doesn't the current implementation mean we're passing both header_name and header_value from ngx.req.set_header(header_name, header_value), to replace_dashes_lower?

We can probably patch this set_header function with a function that takes exactly 2 arguments, then use the first (header_name) to invalidate the index.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed to

  req.set_header = function(name, value)
    local normalized_header = replace_dashes_lower(name)

I did not choose the

  req.set_header = function(...)
    local args = table.unpack(...)
    local normalized_header = replace_dashes_lower(args[1])

I feel that this will degrade performance.

Signed-off-by: tzssangglass <[email protected]>
@VicYP VicYP requested a review from fffonion December 17, 2024 09:35
Signed-off-by: tzssangglass <[email protected]>
@fffonion fffonion merged commit f85f921 into master Dec 18, 2024
6 checks passed
@fffonion fffonion deleted the KAG-5963 branch December 18, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants