Skip to content

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

Closed

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

Activity

  1. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    👋 Hello @Aias00

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

  2. hengyuss commented on Aug 2, 2026

    @hengyuss
    Contributor

    /assign

  3. Aias00 commented on Aug 2, 2026

    @Aias00
    ContributorAuthor

    Follow-up verification note (2026-08-02 audit) — severity/accuracy clarification.

    The buffering of non-binary request bodies is intentional: WebClientPlugin.java:79-83 streams byte-type bodies (outputMessage.writeWith(body)) but joins everything else via DataBufferUtils.join(body), with the inline comment "fix chinese garbled code". So the buffering itself is a deliberate tradeoff, not a bug.

    The genuine defect here is narrower and worth keeping the issue for: the no-arg DataBufferUtils.join(body) enforces no size limit — shenyu.httpclient.maxInMemorySize is not applied on this path. A large non-binary request body is fully buffered into heap with no cap, which is a real memory exposure under the webClient strategy (the netty strategy streams via nettyOutbound.send).

    Suggested reframing: keep the issue open but scope it to "apply maxInMemorySize to the DataBufferUtils.join(body) path" rather than "stop buffering non-binary bodies".

  4. renxf0319 commented on Aug 19, 2026

    @renxf0319
    Contributor

    可否将MULTIPART_FORM_DATA 加入到MediaTypeUtils 的白名单?

  5. Aias00 commented on Aug 19, 2026

    @Aias00
    ContributorAuthor

    可否将MULTIPART_FORM_DATA 加入到MediaTypeUtils 的白名单?

    @hengyuss

  6. hengyuss commented on Aug 19, 2026

    @hengyuss
    Contributor

    可否将MULTIPART_FORM_DATA 加入到MediaTypeUtils 的白名单?

    好的,我看一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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