Aias00 opened a new issue, #6467:
URL: https://github.com/apache/shenyu/issues/6467
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
When `shenyu.httpclient.strategy=webClient` is enabled, `WebClientPlugin`
aggregates most non-binary request bodies before writing them upstream:
```java
if (MediaTypeUtils.isByteType(mediaType)) {
return outputMessage.writeWith(body);
}
// fix chinese garbled code
return outputMessage.writeWith(DataBufferUtils.join(body));
```
`MediaTypeUtils.isByteType(...)` only treats a small set of streaming/binary
media types as pass-through, such as SSE, multipart mixed, image types, NDJSON,
PDF, and octet-stream. Common API request types like JSON, XML, text, and
`application/x-www-form-urlencoded` go through `DataBufferUtils.join(body)`.
That means the WebClient HTTP strategy changes proxy semantics from
streaming to full request-body buffering for ordinary API traffic. Large
JSON/XML/form uploads are accumulated in gateway memory before the upstream
request is sent.
This differs from the Netty strategy, which streams the request body
directly:
```java
return nettyOutbound.send(body.map(dataBuffer -> ((NettyDataBuffer)
dataBuffer).getNativeBuffer()));
```
The configured WebClient codec limit (`shenyu.httpclient.maxInMemorySize`)
does not appear to bound this explicit `DataBufferUtils.join(body)` call.
### Expected Behavior
The WebClient strategy should preserve streaming/backpressure semantics for
proxied request bodies, or it should enforce a clear configured size limit
before aggregating.
Switching from `netty` to `webClient` should not silently make normal
JSON/XML/form requests memory-proportional in the gateway.
### Steps To Reproduce
1. Start ShenYu with `shenyu.httpclient.strategy=webClient`.
2. Proxy a large `application/json`, `text/plain`, XML, or form request
through an HTTP route.
3. `WebClientPlugin` calls `DataBufferUtils.join(body)` and aggregates the
full request body before writing it upstream.
4. Memory usage grows with request body size, and the upstream does not
receive a streaming body as it does under the Netty strategy.
### Environment
```markdown
ShenYu version(s): current master
```
### Debug logs
_No response_
### Anything else?
Relevant current-master files:
-
`shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java`
-
`shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/NettyHttpClientPlugin.java`
-
`shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/utils/MediaTypeUtils.java`
-
`shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-httpclient/src/main/java/org/apache/shenyu/springboot/starter/plugin/httpclient/HttpClientPluginConfiguration.java`
--
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]