header_rewrite: add sort-destination operator#13424
Open
juanthropic wants to merge 9 commits into
Open
Conversation
Adds a pure, TS-API-free sort_query() that stably sorts a URL query string's parameters by name, plus a Catch2 unit test. This helper is reused by the new sort-destination operator and, in a later PR, by the cache/parent-key operators.
Adds OperatorSortDestination, which stably sorts the request URL's query parameters by name using the new sort_query() helper. Useful for origin normalization, not just cache keys.
Verifies that an unsorted client query is forwarded to the origin sorted by header_rewrite's sort-destination operator.
Adds tests for a trailing '&' and for a value containing '=', both flagged during code review as untested-but-correct paths.
Sorting only reorders tokens, so the output length equals the input length; reserving it up front avoids the geometric-growth reallocations std::string would otherwise do while appending in the loop.
split matches how other languages name this operation (Python str.split, Go strings.Split); tokenize implied a distinction from splitting that was not intended.
An empty query tuple (leading '&' or '&&') sorts to the front and is silently absorbed by the join loop's emptiness check, regardless of position. Only the trailing case was previously covered.
rm-destination handles only QUERY, PATH, and PORT. Document that any other part is a no-op leaving the destination unchanged, so rule authors know it does not error.
sort-destination supports only QUERY. Document that any other part is a no-op leaving the destination unchanged, matching the sibling rm-destination wording.
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.
Add a
sort-destination QUERYoperator to header_rewrite that stablysorts the request URL's query parameters by name. Normalizing parameter
order lets varied client query strings map to one origin request, which
helps origin-side caching and dedup.
The sort logic lives in a new pure, TS-API-free
sort_query()helperwith its own unit test, kept separate from the operator so the
cache-key and parent-key operators can reuse it in a later PR.
sort_query()uses a stable sort, so duplicate-named parameters keeptheir relative order.
&are dropped.QUERYis the only supported part; any other part is ano-op, matching the sibling
rm-destinationwording.Covered by a Catch2 unit test for the helper and an end-to-end Proxy
Verifier test that checks an unsorted client query reaches the origin
sorted.