hanzhe-one opened a new pull request, #7915: URL: https://github.com/apache/shenyu/pull/7915
Fixes #7907. The response-transformer system prompt asks the model for a complete HTTP/1.1 response including the status line, but `AiResponseTransformerDecorator` only applied the generated headers and body. Nothing parsed the status, so a model answering `HTTP/1.1 404 Not Found` still returned the upstream `200`. ### Change Parse the generated status line before the response is committed and apply it via `setStatusCode`: - The status line is only accepted as the first non-empty line of the model output (after stripping markdown fences), so a status-looking header value further down cannot change the status. - The code must be one the HTTP specification defines (`HttpStatus.resolve`); otherwise the generated status is ignored and the upstream status is retained. - `204`/`304` are applied without a body: the generated `Content-Type`/`Content-Length`/`Transfer-Encoding` headers are dropped and no buffer is written. - An omitted/invalid status, and the existing "no usable body" fallback, keep the upstream status. - Header extraction now accepts `HTTP/1.0` status lines too (previously only `HTTP/1.1`), and the prompt states that the status line is applied and that 204/304 must not carry a body. The transformed-response branch is extracted into `applyTransformedResponse` so `writeWith` stays under the checkstyle method-length limit. ### Tests `AiResponseTransformerPluginTest` gains regressions for the cases named in the issue: | Case | Expectation | | --- | --- | | Generated `404` over upstream `200` | `404` with the transformed body | | Generated `201` over upstream `500` | `201` | | Generated `999` (not a spec code) | upstream status kept | | No status line | upstream status kept | | Generated `204` | `204`, no body, no `Content-Type` | | Status-looking value in a header | ignored | | `HTTP/1.0` status line | headers still extracted | All 64 tests in `shenyu-plugin-ai-response-transformer` pass locally, including checkstyle. The full `-am` build additionally runs `shenyu-plugin-ai-common`, where `OpenAiModelFactoryTest`/`DeepSeekModelFactoryTest` fail on this machine with `Unable to establish loopback connection` — an environment issue (NIO loopback is broken locally), unrelated to this change. - [x] I have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [x] I submit test cases (unit or integration tests) that back your changes. - [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true` (full build not run; module tests + checkstyle pass). -- 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]
