Skip to content

fix(gzip): skip decompression for nginx-delegated gzip in log collect#13098

Open
sihyeonn wants to merge 1 commit intoapache:masterfrom
sihyeonn:fix/gzip-log-decompress-warning
Open

fix(gzip): skip decompression for nginx-delegated gzip in log collect#13098
sihyeonn wants to merge 1 commit intoapache:masterfrom
sihyeonn:fix/gzip-log-decompress-warning

Conversation

@sihyeonn
Copy link
Contributor

Description

Closes #13093

When the gzip plugin delegates compression to the nginx gzip module via response.set_gzip(), the Content-Encoding: gzip header is set immediately during header_filter, but the actual compression happens in nginx's output filter chain after body_filter_by_lua completes.

This causes log-util.collect_body() to see Content-Encoding: gzip and attempt to decompress a body that is still plaintext, resulting in repeated INFLATE: data error warnings in the error log.

Root cause

The execution order is:

  1. header_filter → gzip plugin sets Content-Encoding: gzip
  2. body_filter_by_lua → log plugin calls collect_body(), sees gzip header, tries to inflate plaintext → error
  3. nginx output filter → actual gzip compression happens here

Fix

Set ctx.gzip_set = true in the gzip plugin after successful set_gzip(), and check this flag in collect_body() to skip decompression. The raw (uncompressed) body is stored directly for logging.

This follows the same pattern as ctx.brotli_matched used by the brotli plugin.

When the gzip plugin delegates compression to the nginx gzip module
via set_gzip(), the Content-Encoding header is set immediately in
header_filter, but the actual compression happens in nginx's output
filter chain after body_filter_by_lua completes.

This causes log-util's collect_body() to see Content-Encoding: gzip
and attempt to decompress a body that is still plaintext, resulting
in "INFLATE: data error" warnings.

Set ctx.gzip_set flag after successful set_gzip() and check it in
collect_body() to skip decompression, storing the raw body directly.
This follows the same pattern as ctx.brotli_matched in the brotli
plugin.

Closes apache#13093

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Mar 18, 2026
@Baoyuantop Baoyuantop requested a review from Copilot March 18, 2026 10:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates response-body collection logic used by APISIX logger plugins to account for responses where APISIX gzip is enabled, avoiding unnecessary (and potentially incorrect) content-decoding attempts.

Changes:

  • Mark requests where the gzip plugin successfully enables gzip via ctx.gzip_set.
  • Skip response-body decoding in log-util.collect_body when ctx.gzip_set is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apisix/utils/log-util.lua Avoids attempting to decode response bodies based on Content-Encoding when APISIX gzip has been enabled for the request.
apisix/plugins/gzip.lua Sets ctx.gzip_set after successfully calling response.set_gzip() so downstream logging can adjust behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 154 to +165
local ok, err = response.set_gzip({
buffer_num = buffers.number,
buffer_size = buffers.size,
compress_level = conf.comp_level,
})
if not ok then
core.log.error("failed to set gzip: ", err)
return
end

ctx.gzip_set = true

Comment on lines 376 to 379
local response_encoding = ngx_header["Content-Encoding"]
if not response_encoding then
if not response_encoding or ctx.gzip_set then
ctx.resp_body = final_body
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: APISIX incorrectly attempts to decompress uncompressed response bodies in log plugins

2 participants