apache / apache/shenyu

[BUG] WebClientPlugin: wasted/duplicate request-header copy + ineffective request-side dedup

Open Beginner friendly
#6,572 1 comment 0 reactions 0 assignees View on GitHub
plugin: http-client priority: high type: performance
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
Per proxied request: line 62 builds `new HttpHeaders(request.getHeaders())` (full copy) and applies `duplicateHeaders(...)` on it, but the line 67 `.headers(...)` lambda re-reads `exchange.getRequest().getHeaders()` and `addAll`s the raw, un-deduplicated request headers — the deduplicated `httpHeaders` from line 62 is never wired into the outbound request. So the request-side dedup is ineffective AND there's a wasted full `HttpHeaders` copy per request. The response side (97-100) also builds an intermediate `HttpHeaders` then `putAll`s into the exchange response (a second copy).

## Location
```
shenyu-plugin-httpclient/.../WebClientPlugin.java:62-67 (request side), 97-100 (response side)
```

## Impact
~4 `LinkedHashMap`-backed `HttpHeaders` allocations + ~40 entry re-insertions per request (for ~10 headers). Single most impactful GC fix on the proxy hot path; also a latent correctness concern (request-side `REQ_UNIQUE_HEADER` dedup has no effect).

## Suggested fix
Pass the line-62 `httpHeaders` into the lambda instead of re-reading `exchange.getRequest().getHeaders()`; for the response, write directly into `exchange.getResponse().getHeaders()` instead of allocating an intermediate `HttpHeaders`.

## Related existing issue(s)
None

_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Open shenyu-plugin-httpclient/.../WebClientPlugin.java and inspect lines 62-67 and 97-100. Trace how request headers enter the outbound request and how response headers are copied, then confirm the existing behavior around deduplication and copying. Done means the prepared request headers are used, response headers avoid the intermediate copy, and proxy header behavior remains correct.

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
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.