Skip to content

[BUG] WebClient HTTP strategy fully buffers non-binary request bodies before proxying #6467

Description

@Aias00

Is there an existing issue for this?

  • 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:

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:

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

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions