klT45 opened a new pull request, #7916: URL: https://github.com/apache/shenyu/pull/7916
### Summary Fixes #7906. `AiResponseTransformerPlugin` kept a reference to the live `ServerHttpRequest` and `AiResponseTransformerTemplate` called `originalRequest.getBody()` again while the response was being written. By then the downstream chain had already consumed the one-shot request body, so the prompt lost the request body (or the second subscription failed) even though the backend received the full payload. This change captures a bounded snapshot of the request body while the downstream chain consumes it, and builds the prompt from that snapshot instead of subscribing to the transport body a second time. ### Changes - **New `CachedRequestBodyDecorator`** (`ServerHttpRequestDecorator`): forwards the original body stream untouched, copying every buffer through a read-only view without moving its read position into a UTF-8 snapshot capped at 1 MiB. Bodies over the cap are still forwarded unchanged; the snapshot is dropped and the prompt keeps the previous empty request body, so memory stays bounded. - **`AiResponseTransformerPlugin.doExecute`**: installs the decorator on the mutated exchange before `chain.execute(...)` and passes it to the template. - **`AiResponseTransformerTemplate`**: adds a constructor that reads the captured body lazily at response time; the existing two-argument constructor is kept for callers without a snapshot. - No new configuration, dependency, or change for downstream consumers of the request stream. ### Tests `./mvnw.cmd -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer verify -Djacoco.skip=true` - 62 tests pass, checkstyle 0 violations, RAT 0 unapproved. - `CachedRequestBodyDecoratorTest`: forwarding + capture, multi-buffer order, empty/no body, overflow still forwards but drops the snapshot, cancellation captures only the forwarded bytes. - `AiResponseTransformerTemplateTest`: a one-shot POST/PUT body consumed by the downstream chain is present in the assembled prompt (empty before the fix); an overflowing snapshot keeps the prompt body empty; the no-body controls behave as before. - `AiResponseTransformerPluginTest`: asserts the exchange request is replaced by the snapshot decorator. <!-- 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. - [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. Module-scoped `verify` (tests + checkstyle + RAT) passed; a full clean install was not run locally. --> -- 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]
