This is an automated email from the ASF dual-hosted git repository.

baoyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new fb21466ab fix(file-logger): incorrectly attempts to decompress 
uncompressed response body (#13100)
fb21466ab is described below

commit fb21466ab6d1914c1219d873ec2e56718d826627
Author: hachi029 <[email protected]>
AuthorDate: Wed Apr 1 18:30:19 2026 +0800

    fix(file-logger): incorrectly attempts to decompress uncompressed response 
body (#13100)
---
 apisix/plugins/gzip.lua   |  2 +-
 apisix/utils/log-util.lua |  2 +-
 t/plugin/file-logger2.t   | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/apisix/plugins/gzip.lua b/apisix/plugins/gzip.lua
index dfd0f10c0..f29baed84 100644
--- a/apisix/plugins/gzip.lua
+++ b/apisix/plugins/gzip.lua
@@ -160,7 +160,7 @@ function _M.header_filter(conf, ctx)
         core.log.error("failed to set gzip: ", err)
         return
     end
-
+    ctx.gzip_matched = true
     if conf.vary then
         core.response.add_header("Vary", "Accept-Encoding")
     end
diff --git a/apisix/utils/log-util.lua b/apisix/utils/log-util.lua
index f1fea458d..35a709814 100644
--- a/apisix/utils/log-util.lua
+++ b/apisix/utils/log-util.lua
@@ -399,7 +399,7 @@ function _M.collect_body(conf, ctx)
             end
 
             local response_encoding = ngx_header["Content-Encoding"]
-            if not response_encoding then
+            if not response_encoding or ctx.gzip_matched then
                 ctx.resp_body = final_body
                 return
             end
diff --git a/t/plugin/file-logger2.t b/t/plugin/file-logger2.t
index 706f401fe..8cbaabd72 100644
--- a/t/plugin/file-logger2.t
+++ b/t/plugin/file-logger2.t
@@ -514,3 +514,63 @@ contain with target
 --- response_body
 contain target body hits with expr
 skip unconcern body
+
+
+
+=== TEST 15: collecting response body gzipped by APISIX
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "plugins": {
+                        "file-logger": {
+                            "path": "file-with-uncompressed-resp-body.log",
+                            "include_resp_body": true
+                        },
+                        "gzip": {
+                             "min_length": 10
+                     }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/hello"
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            local code = t("/hello", ngx.HTTP_GET, nil, nil, 
{['Accept-Encoding']='gzip'})
+            local fd, err = io.open("file-with-uncompressed-resp-body.log", 
'r')
+            local msg
+
+            if not fd then
+                core.log.error("failed to open file: 
file-with-uncompressed-resp-body.log, error info: ", err)
+                return
+            end
+
+            -- note only for first line
+            msg = fd:read()
+
+            local new_msg = core.json.decode(msg)
+            ngx.status = code
+            if new_msg.response ~= nil and new_msg.response.body == "hello 
world\n" then
+                ngx.say('contain with target')
+            end
+        }
+    }
+--- no_error_log
+try decode compressed data err: inflate gzip err: INFLATE: data error
+--- response_body
+contain with target

Reply via email to