Sean-Walker0 opened a new pull request, #7418:
URL: https://github.com/apache/shenyu/pull/7418
Fixes #6510
<!-- Describe your PR here; e.g. Fixes #issueNo -->
## Modifications
`ModifyResponsePlugin` applied the `replaceHeaderKeys` map with
`httpHeaders.replace(key, Collections.singletonList(value))`.
`HttpHeaders.replace` keeps the **key** and replaces the **values**, so a rule
`{"X-Old": "X-New"}` against an upstream `X-Old: abc` returned `X-Old: X-New`
instead of renaming the header to `X-New: abc` — contradicting the documented
contract (`key: oldHeaderKey, value: newHeaderKey`) and the sibling
`RequestPlugin#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:
```java
replaceHeaderMap.forEach((key, value) -> {
List<String> values = httpHeaders.get(key);
if (Objects.nonNull(values)) {
httpHeaders.addAll(value, values);
httpHeaders.remove(key);
}
});
```
## Verifying this change
- [x] New
`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.
- [x] New
`ModifyResponsePluginTest#testReplaceHeaderKeysLeavesMissingSourceKeyUntouched`
— a configured source key absent from the response stays a no-op.
- [x] `./mvnw -pl shenyu-plugin/shenyu-plugin-modify-response -am test -B` —
13/13 module tests green, checkstyle clean.
## Notes
- **Behavior change (the bug fix itself):** responses configured with
`replaceHeaderKeys` now 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.
- Side finding (not addressed here): `addHeaders` uses `httpHeaders::add`,
which appends to existing values rather than replacing them; that is a separate
semantic question for maintainers.
- Orthogonality: no open PR touches `shenyu-plugin-modify-response`
(verified against the file lists of all 92 open PRs).
Make sure that:
- [x] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your
changes.
- [x] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true` (module-scoped:
`shenyu-plugin/shenyu-plugin-modify-response` with `-am`, tests + checkstyle
green).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]