shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[BUG] Request plugin add* operations overwrite existing values like set*

Open SouthwestAsiaFloat opened this issue 5 months ago β€’ 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Current Behavior

In the Request plugin, addParameters, addHeaders, and addCookies behave the same as their corresponding set* operations when the target key already exists.

For example, when the original request contains:

?tag=old

and the Request plugin is configured with:

{
  "parameter": {
    "addParameters": {
      "tag": "new"
    }
  }
}

the downstream service receives:

tag=new

instead of preserving the original value.

The current implementation routes both add* and set* operations through the same logic based on set(), resulting in identical behavior.

Expected Behavior

add* operations should preserve existing values and append the configured value, while set* operations should continue to overwrite existing values.

Example:

Original request:
?tag=old

addParameters(tag=new)

Expected:

tag=old&tag=new

or an equivalent multi-value representation.

The same semantic distinction should apply to headers and cookies.

Steps To Reproduce

  1. Enable the Request plugin.

  2. Configure a Request plugin rule:

{
  "parameter": {
    "addParameters": {
      "tag": "new"
    }
  }
}
  1. Send a request containing an existing query parameter:
curl "http://localhost:9195/http/request-bug/echo?tag=old"
  1. Observe that the downstream service receives:
tag=new

instead of preserving the original value and appending the new value.

Environment

ShenYu version: 2.4.0
Apache ShenYu master branch
Module: shenyu-plugin-request
Local standalone deployment

Debug logs

RequestHandle documents addHeaders as "need to be appended new header value", while setHeaders is documented as covering/overwriting the value.

ModifyResponsePlugin also implements:

addHeaders -> HttpHeaders.add(...) setHeaders -> HttpHeaders.set(...)

which suggests that add and set are intended to have different semantics.

Anything else?

I would be happy to work on a PR if this behavior is confirmed as a bugπŸ˜„.

SouthwestAsiaFloat avatar Jun 07 '26 04:06 SouthwestAsiaFloat

πŸ‘‹ Hello @yuluo-yx

A new issue has been opened by @SouthwestAsiaFloat:

  • Title: [BUG] Request plugin add* operations overwrite existing values like set*
  • Link: https://github.com/apache/shenyu/issues/6360

Please review when you have time. Thank you! πŸ™

github-actions[bot] avatar Jun 07 '26 04:06 github-actions[bot]

hi, thanks for your issue report, can you fix this?

Aias00 avatar Jun 08 '26 09:06 Aias00

hi, thanks for your issue report, can you fix this?

I would like to fix it😊

SouthwestAsiaFloat avatar Jun 08 '26 09:06 SouthwestAsiaFloat

hi, thanks for your issue report, can you fix this?

I would like to fix it😊

okay, glad to hear. just submit a pr , and i will review

Aias00 avatar Jun 08 '26 09:06 Aias00