This repository was archived by the owner on Apr 24, 2026. It is now read-only.
fix(descriptor): use _normalize_header_name in header fast-path#154
Open
levleontiev wants to merge 3 commits into
Open
fix(descriptor): use _normalize_header_name in header fast-path#154levleontiev wants to merge 3 commits into
levleontiev wants to merge 3 commits into
Conversation
The two-step fast-path for header lookup applied only one of the two transformations OpenResty performs (lowercase + hyphen→underscore): name_underscore = gsub(name, "-", "_") -- preserves case → X_E2E_Key name_lower = lower(name) -- preserves hyphens → x-e2e-key For any limit_key using an uppercase+hyphenated name (e.g. X-E2E-Key) with an OpenResty-normalized header table (x_e2e_key), both lookups miss. Every such request fell through to the O(n) pairs() scan. Fix: replace the two broken lookups with a single call to the already- defined _normalize_header_name helper, which applies both transformations together. The O(n) fallback is retained as a last-resort but should no longer be reached for normal hyphenated header names. AC-7c (new scenario) exercises the uppercase+hyphenated case that the old fast-path could not handle without the fallback scan.
AC-7b already tests lowercase hyphenated name (x-e2e-key → x_e2e_key). AC-7c exercises the case the old two-step fast-path silently missed: an uppercase+hyphenated limit_key (X-E2E-Key) where OpenResty has normalized the header to x_e2e_key. The old code would have fallen through to the O(n) pairs() scan; the fixed code resolves it in O(1).
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
The two-step fast-path for header lookup in
descriptor.luawas applying only one transformation at a time, while OpenResty applies both simultaneously (lowercase + hyphen→underscore):Fix
Replace with a single call to the already-defined
_normalize_header_namehelper that applies both transformations:Impact
header:X-E2E-Key,header:X-API-Key) with an OpenResty-normalized header table was doing an O(n)pairs()scan on every request instead of an O(1) lookup.Why tests didn't catch this
AC-7b uses a lowercase limit key (
header:x-e2e-key), sostring_gsub("x-e2e-key", "-", "_")="x_e2e_key"— the fast-path happened to work. AC-7c (new) covers the uppercase case.🤖 Generated with Claude Code