Search before asking
Apache ShenYu Component
shenyu-plugin
What happened
ModifyResponseRuleHandle.replaceHeaderKeys is documented as a header-name replacement map:
/**
* replace header map
* key: oldHeaderKey, value: newHeaderKey.
*/
private Map<String, String> replaceHeaderKeys;
But ModifyResponsePlugin applies the map like this:
if (MapUtils.isNotEmpty(this.ruleHandle.getReplaceHeaderKeys())) {
Map<String, String> 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:
{
"replaceHeaderKeys": {
"X-Old": "X-New"
}
}
will return:
instead of renaming the header to:
X-New: <original X-Old values>
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
- Enable the modify-response plugin.
- Configure a rule with
replaceHeaderKeys mapping X-Old to X-New.
- Let the upstream return
X-Old: abc.
- 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?
Search before asking
Apache ShenYu Component
shenyu-plugin
What happened
ModifyResponseRuleHandle.replaceHeaderKeysis documented as a header-name replacement map:But
ModifyResponsePluginapplies the map like this:HttpHeaders.replace(key, values)keeps the same header key and replaces its values. Therefore a rule such as:{ "replaceHeaderKeys": { "X-Old": "X-New" } }will return:
instead of renaming the header to:
Expected behavior
replaceHeaderKeysshould rename response header keys according to the documentedoldHeaderKey -> newHeaderKeymapping 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
replaceHeaderKeysmappingX-OldtoX-New.X-Old: abc.X-Old: X-Newinstead ofX-New: abc.Debug logs
No response
Environment
Current
masterbranch.Are you willing to submit a PR?