fix(plugin): rename header keys instead of overwriting values in modify-response - #7418
Open
Sean-Walker0 wants to merge 1 commit into
Open
Sean-Walker0 wants to merge 1 commit into
Sean-Walker0 wants to merge 1 commit into
Conversation
…fy-response
ModifyResponsePlugin applied the replaceHeaderKeys map with
HttpHeaders.replace(key, singletonList(value)), which keeps the old
header name and overwrites its values: a rule {"X-Old": "X-New"} on
an upstream response X-Old: abc produced X-Old: X-New instead of
renaming the header to X-New: abc. This contradicts the documented
contract of ModifyResponseRuleHandle.replaceHeaderKeys (key:
oldHeaderKey, value: newHeaderKey) and the sibling
RequestPlugin#replaceHeaderKey, which renames the key and preserves
the values.
Rename the header key and carry the original values over, mirroring
the request-side implementation. Regression tests cover the rename
(multiple values preserved, old key dropped) and the missing
source key no-op.
Fixes apache#6510
This branch has not been deployed
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.
Fixes #6510
Modifications
ModifyResponsePluginapplied thereplaceHeaderKeysmap withhttpHeaders.replace(key, Collections.singletonList(value)).HttpHeaders.replacekeeps the key and replaces the values, so a rule{"X-Old": "X-New"}against an upstreamX-Old: abcreturnedX-Old: X-Newinstead of renaming the header toX-New: abc— contradicting the documented contract (key: oldHeaderKey, value: newHeaderKey) and the siblingRequestPlugin#replaceHeaderKey, which renames the key while preserving the values.The fix renames the header key and carries the original values over, mirroring the request-side implementation:
Verifying this change
ModifyResponsePluginTest#testReplaceHeaderKeysRenamesKeyAndKeepsValues— fails on the pre-fix code (expected: <false> but was: <true>, the old key survived and the values were overwritten) and passes after the fix; it also asserts multiple header values are preserved under the new key.ModifyResponsePluginTest#testReplaceHeaderKeysLeavesMissingSourceKeyUntouched— a configured source key absent from the response stays a no-op../mvnw -pl shenyu-plugin/shenyu-plugin-modify-response -am test -B— 13/13 module tests green, checkstyle clean.Notes
replaceHeaderKeysnow return the header under the new name with the original values, instead of the old name with the new name as the value. This matches the rule-handle javadoc and the request-plugin sibling.addHeadersuseshttpHeaders::add, which appends to existing values rather than replacing them; that is a separate semantic question for maintainers.shenyu-plugin-modify-response(verified against the file lists of all 92 open PRs).Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true(module-scoped:shenyu-plugin/shenyu-plugin-modify-responsewith-am, tests + checkstyle green).