[BUG] ModifyResponse replaceHeaderKeys changes header value instead of header name
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues.
### Apache ShenYu Component
shenyu-plugin
### What happened
`ModifyResponseRuleHandle.replaceHeaderKeys` is documented as a header-name replacement map:
```java
/**
* replace header map
* key: oldHeaderKey, value: newHeaderKey.
*/
private Map replaceHeaderKeys;
```
But `ModifyResponsePlugin` applies the map like this:
```java
if (MapUtils.isNotEmpty(this.ruleHandle.getReplaceHeaderKeys())) {
Map replaceHeaderMap = this.ruleHandle.getReplaceHeaderKeys();
replaceHeaderMap.forEach((key, value) -> httpHeaders.replace(key, Collections.singletonList(value)));
}
```
`HttpHeaders.replace(key, values)` keeps the same header key and replaces its values. Therefore a rule such as:
```json
{
"replaceHeaderKeys": {
"X-Old": "X-New"
}
}
```
will return:
```text
X-Old: X-New
```
instead of renaming the header to:
```text
X-New:
```
### Expected behavior
`replaceHeaderKeys` should rename response header keys according to the documented `oldHeaderKey -> newHeaderKey` mapping while preserving the original header values, or the field should be renamed/re-documented if the intended behavior is value replacement. The current implementation does neither and produces incorrect response headers.
### How to reproduce
1. Enable the modify-response plugin.
2. Configure a rule with `replaceHeaderKeys` mapping `X-Old` to `X-New`.
3. Let the upstream return `X-Old: abc`.
4. The gateway returns `X-Old: X-New` instead of `X-New: abc`.
### Debug logs
_No response_
### Environment
Current `master` branch.
### Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with ModifyResponsePlugin and the replaceHeaderKeys field in ModifyResponseRuleHandle, then trace how response headers are passed to HttpHeaders. Reproduce the X-Old to X-New case from the issue and verify that the header name changes while its original value is preserved. Add or update focused plugin tests if the existing test locations are found during the investigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100