Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
core.request.set_header/add_header(and clearing a header withnil) are supposed to drop the cachedctx.varvalue of that header, but the value read through the usual spelling stays stale.modify_headerclearsctx.var["http_" .. str_lower(header_name)], i.e.http_x-fooforX-Foo.ctx.varhowever cacheshttp_*lookups under whatever key the caller used, and routevars, plugins and most code read the underscore formhttp_x_foo. So this sequence returns the old value:The same happens after
core.request.set_header(ctx, "X-Foo", nil): a header removed before proxying is still visible to every later phase that readsctx.var.http_x_foo, and a route whosevarsmatched on that header has already put it in the cache.Since nginx treats
$http_*names case-insensitively and with-equal to_, any spelling (http_x_foo,http_x-foo,http_X-Foo, ...) can end up as its own cache key, so clearing one more spelling inmodify_headerwould still leave the others. Instead,ctx.varnow stores everyhttp_*entry, on read and on write, under the normalized key (lower case,-replaced with_), the same name it already used to fetch the nginx variable. Each header then has a single cache entry, and the existing invalidation inmodify_header(which goes through__newindex) clears it whatever spelling the caller passes. Lookups with the normalized spelling still hit the cache directly; other spellings pay one lower/gsub before hitting the shared entry.A test in
t/core/request.treads the header under three spellings after set, add, clear and a directctx.varwrite; it fails without this change.No documentation describes this caching, so there is nothing to update in
docs/.Checklist