nic-6443 opened a new pull request, #14232:
URL: https://github.com/apache/apisix/pull/14232
### Description
Loggers with `include_resp_body` decode a compressed response body before
logging it, and two kinds of input made that decode fail, so the log got a `try
decode compressed data err` warning and the raw compressed bytes as the body.
The first is an empty body sent with `Content-Encoding: gzip`, such as a
204, a 304 or a 200 with `Content-Length: 0`. `inflate_gzip("")` fails with
`INFLATE: Data error, no input bytes`. `collect_body()` now treats an empty
buffered body as an empty body and skips the decoder.
The second is a compressed body longer than `max_resp_body_bytes`.
`hold_body_chunk()` cuts the buffer at the limit, and inflating a cut stream
always fails. zlib has already produced the plaintext for the bytes it got by
then, but `inflate_gzip()` threw it away when it returned the error. When the
buffer reached the limit, `collect_body()` now decodes it as a possibly cut
stream. It keeps the plaintext decoded so far and caps it at
`max_resp_body_bytes`, without a warning. A complete body that is exactly as
long as the limit goes down the same path and still decodes in full.
The decoders in `content-decode.lua` take an optional `max_output` for this.
For gzip, it maps to a new `partial` flag on `inflate_gzip()`, which reuses its
existing `max_output` cap. Running out of input or reaching the cap returns the
output so far instead of an error. A data error is still an error, so a garbled
stream is still reported. br follows the same rules: it skips `finish()` (which
raises `incomplete compressed stream`) and stops reading input once the cap is
reached. Callers that don't pass the flag behave as before, including
`request-decompress`, which keeps its `exceeded` return.
A body that fails to decode without reaching the limit (for example a
non-gzip body labelled gzip) still logs the warning and the raw body.
`response-rewrite` with `filters` used the same decoder and logged `filters
may not work as expected` for an empty compressed body. It now skips decoding
an empty body and applies the filters to the empty string, the same way it
handles an uncompressed empty body. Its handling of a body cut at
`max_resp_body_size` is not changed here. The rewritten body goes to the
client, not into a log, so a decoded prefix is not obviously the right output
there.
The logger docs now say what `max_resp_body_bytes` means for a compressed
response.
Tests in `t/plugin/file-logger2.t` cover empty gzip bodies on 200 / 204 /
304, gzip bodies cut at the limit (one that hits the plaintext cap and one that
runs out of input first), a complete gzip body exactly at the limit, a non-gzip
body under the limit that still warns, and the br equivalents.
`t/plugin/response-rewrite3.t` covers the empty gzip body with filters.
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not,
please discuss on the [APISIX mailing
list](https://github.com/apache/apisix/tree/master#community) first)
--
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]