Aias00 opened a new issue, #7908:
URL: https://github.com/apache/shenyu/issues/7908

   ### Behavior and reproduction
   
   A gzip-compressed upstream response becomes an invalid client response when 
AI transformation fails or returns an invalid body: the plugin sends 
decompressed plaintext but retains `Content-Encoding: gzip`.
   
   Executed at `fda742c48e7f553c9964cf74b36732326d0fde00` through the real 
response decorator:
   
   1. Set upstream status 200, Content-Encoding gzip, and supply gzip bytes for 
`{"customer":"alice"}`.
   2. Make the mocked ChatClient content publisher fail.
   3. Consume the fallback response.
   
   Observed: the body is literal UTF-8 `{"customer":"alice"}`, while the final 
header is still `Content-Encoding: gzip`. The actual utility updates 
Content-Length to 20; it does **not** remove the compression header. A 
gzip-decoding client therefore cannot decode this fallback representation.
   
   ### Location and cause
   
   - [Decode upstream gzip into 
originalResponseBody](https://github.com/apache/shenyu/blob/fda742c48e7f553c9964cf74b36732326d0fde00/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java#L318)
   - [Invalid-output fallback writes the decoded 
String](https://github.com/apache/shenyu/blob/fda742c48e7f553c9964cf74b36732326d0fde00/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java#L371)
   - [Model-error fallback writes the decoded 
String](https://github.com/apache/shenyu/blob/fda742c48e7f553c9964cf74b36732326d0fde00/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java#L376)
   
   The fallback uses the decoded prompt representation rather than the original 
wire bytes, without normalizing Content-Encoding.
   
   ### Expected behavior / suggested repair
   
   On fallback, either return the original compressed bytes with their encoding 
metadata, or deliberately emit the decoded representation and remove/update the 
encoding metadata. Keep prompt decoding separate from the fallback wire 
representation. Cover model error, invalid generated body, gzip and 
uncompressed controls, and assert client-visible bytes plus headers.
   
   ### Scope / related issues
   
   Functional response corruption, medium severity. Distinct from #6811 
(Inflater/resource closure), #6756 (successful-output header mutation timing), 
and #6512 (gzip in token/logging paths).
   


-- 
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]

Reply via email to