Sean-Walker0 opened a new pull request, #7820:
URL: https://github.com/apache/shenyu/pull/7820
Fixes #7816
## Modifications
A positive divide rule `requestMaxSize` was only compared against the
`Content-Length` header. Chunked or unknown-length requests report `-1` for
that header, so the comparison succeeded without examining a single body byte —
oversized streaming bodies were forwarded, and the limit only protected
known-length input (the issue's probe: `knownLength=false limit=1
forwardedBytes=2`).
For unknown-length requests the limit is now enforced on the actual bytes:
the request is decorated with a counting body that aborts the stream once the
forwarded size exceeds the configured maximum:
```java
return exchange.mutate().request(new
ServerHttpRequestDecorator(exchange.getRequest()) {
private long forwarded;
@Override
public Flux<DataBuffer> getBody() {
return super.getBody().doOnNext(buffer -> {
forwarded += buffer.readableByteCount();
if (forwarded > maxSize) {
throw new ShenyuException("request entity is too large");
}
});
}
}).build();
```
The known-length fast path (immediate 413 before forwarding) and all other
rule handling are unchanged.
## Verifying this change
- [x] New
`DividePluginTest#doExecuteRejectsChunkedBodyExceedingRequestMaxSize` — posts a
2-byte chunked body (`Transfer-Encoding: chunked`, no `Content-Length`) under a
`requestMaxSize=1` rule; the downstream drains the body and the stream must
abort. Red on the pre-fix code (the body was forwarded completely), green after.
- [x] `./mvnw -pl shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide -am
test -B` — full module 25/25 green (12 pre-existing DividePluginTest cases +
circuit-breaker suite unchanged), checkstyle clean.
## Notes
- Behavior change: chunked/unknown-length requests that exceed a configured
`requestMaxSize` now abort mid-stream instead of being forwarded in full —
matching what the same rule already does for known-length bodies.
- The abort surfaces as an error to the WebFlux pipeline (response typically
not yet committed for streaming bodies, so the global error handler can still
answer); once the body has partially streamed, connection-level termination is
the only correct signal.
- Codec-level `maxInMemorySize` aggregation limits are a separate mechanism
(returning 413 pre-forwarding) and remain untouched.
- Orthogonality: no open PR modifies `DividePlugin` (verified against the
file lists of all 120 open PRs).
Make sure that:
- [x] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your
changes.
- [x] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true` (module-scoped: `shenyu-plugin-divide` with `-am`,
25 tests + checkstyle green).
--
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]