mirror of
https://github.com/alibaba/higress.git
synced 2026-06-01 00:27:26 +08:00
fix(log-request-response): enhance response body logging by checking Content-Encoding (#3074)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user