konlue opened a new pull request, #7786:
URL: https://github.com/apache/shenyu/pull/7786
Fixes #7771.
## Summary
`RequestTemplate.from()` shares header value collections with the template
it copies from. Since `targetProcessor` runs `from` → `request()` → parameter
processors against a long-lived per-method template, dynamic header/cookie
values mutate collections the template still owns: a static
`Collections.singleton` header paired with a dynamic value of the same name
throws `UnsupportedOperationException` before any transport call, and dynamic
cookies accumulate across invocations.
## Modifications
- `RequestTemplate.from()` copies header value collections per entry (`new
ArrayList<>`), giving each invocation independently owned values.
- `RequestHeaderParameterProcessor` copies an existing collection before
appending (both the single-value and map branches).
- `CookieValueParameterProcessor` builds the per-call `Cookie` entry from
the invocation's own header map with a defensive copy, and no longer reads or
mutates the shared template; its previous compute path could also double-append
template values.
## Verifying this change
- [x] New tests: `RequestTemplateTest#testFromCopiesHeaderValues` (mutating
the copy leaves the original untouched),
`RequestHeaderParameterProcessorTest#processArgumentOnStaticSingletonHeaderTest`
(static singleton + dynamic same-name header merges, template value unchanged)
and
`CookieValueParameterProcessorTest#processArgumentDoesNotAccumulateAcrossCalls`
(two invocations stay isolated, template never grows).
- [x] Red-green: with the deep copy and the cookie read-point change
reverted, the singleton and accumulation cases fail with
`UnsupportedOperationException`; with the fix all pass (core 4/4, spring 6/6 +
6/6).
- [x] Targeted tests pass:
```bash
./mvnw -B -ntp -pl shenyu-sdk/shenyu-sdk-core,shenyu-sdk/shenyu-sdk-spring
test
-Dtest='RequestTemplateTest,RequestHeaderParameterProcessorTest,CookieValueParameterProcessorTest'
```
core 4/4, spring 6/6 + 6/6 green.
- [x] Checkstyle passes:
```bash
./mvnw -B -ntp -pl shenyu-sdk/shenyu-sdk-core,shenyu-sdk/shenyu-sdk-spring
checkstyle:check
```
clean.
## Notes
Transport-layer consumers (OkHttp/Http clients, load-balance data) only read
headers, so per-entry copying has no behavioural downside. `request()`'s
shallow outer-map copy stays: after `from()`, the value collections are already
independently owned. A user `ShenyuSdkRequestInterceptor` that appends to an
existing collection could still hit an immutable value list of its own making —
same family of issue, left untouched here since the interceptor map is already
per-request at the outer level.
--
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]