fix(log-request-response): enhance response body logging by checking Content-Encoding (#3074)

This commit is contained in:
Jingze
2025-10-30 10:59:04 +08:00
committed by GitHub
parent af8748d754
commit ccbb542fec
3 changed files with 13 additions and 3 deletions

View File

@@ -355,15 +355,23 @@ func onHttpResponseHeaders(ctx wrapper.HttpContext, config PluginConfig) types.A
return types.ActionContinue
}
// Check Content-Type for response body logging
// Check Content-Type and Content-Encoding for response body logging
contentType := ""
hasContentEncoding := false
for _, header := range headers {
if strings.ToLower(header[0]) == "content-type" {
contentType = header[1]
break
} else if strings.ToLower(header[0]) == "content-encoding" {
hasContentEncoding = true
}
}
// Skip response body logging if content encoding is present (avoid logging compressed content)
if hasContentEncoding {
ctx.DontReadResponseBody()
return types.ActionContinue
}
// Skip response body logging if content type is not in the configured list
if contentType != "" {
shouldLogBody := false