fix(divide): enforce requestMaxSize on chunked request bodies #8033
The streaming guard is the right shape: it only engages when requestMaxSize > 0 and Content-Length is absent, so known-length bodies keep the existing fast path and there is no double accounting with the header check above it.
Two things to consider, neither blocking:
1. forwarded is a mutable field on the anonymous decorator, reset inside Flux.defer. That is correct for the sequential (and retry) case, because each subscription restarts the count. A concurrent second subscription of getBody() on the same exchange would race on it, though. If that can happen through the retry strategy, an AtomicLong removes the doubt; otherwise a comment stating the single-subscription assumption is enough.
2. The 413 is raised from inside the body Flux, so it surfaces from chain.execute(...) rather than from the plugin's return value. The test proves the error type reaches the subscriber, but please confirm it reaches the client as a 413 response body rather than a bare stream error — the header-based path above returns a normal WebFluxResultUtils result, so the two rejection paths would otherwise behave differently at the edge.
Approving; the above can be follow-ups.
/retest
Aias00
Sean-Walker0
Fixes #7816. Supersedes #7820 (approved, but it conflicted with master after #7857 moved the selection/forwarding into
forwardSelectedwith canary routing — this is the same fix rebased onto that structure, as requested in the review follow-up).Modifications
A positive divide rule
requestMaxSizewas only compared against theContent-Lengthheader. Chunked or unknown-length requests report-1, so the comparison succeeded without examining a single body byte — oversized streaming bodies were forwarded.For unknown-length requests the limit is enforced on the actual bytes: the request is decorated with a counting body that resets per subscription (
Flux.defer) and aborts the stream withResponseStatusException(PAYLOAD_TOO_LARGE)(whichGlobalErrorHandleralready honours) once the forwarded size exceeds the maximum. The known-length fast path is unchanged; the decorated exchange is threaded through theforwardSelectedcall so canary selection, attributes and circuit-breaker recording all operate on it.Verifying this change
doExecuteRejectsChunkedBodyExceedingRequestMaxSize— 2-byte chunked body under a 1-byte limit; the downstream drains the body and the stream must abort withResponseStatusExceptioncarryingPAYLOAD_TOO_LARGE. Red on the un-fixed code (verified by temporarily bypassing the decorator), green after../mvnw -pl shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide -am test -B— full module 103/103 green (all canary/circuit-breaker suites from #7857 included), checkstyle clean.Notes
DividePluginon top of current master (the #7857 refactor is already merged here).Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true(module-scoped:shenyu-plugin-dividewith-am, 103 tests + checkstyle green).