summaryrefslogtreecommitdiff
path: root/modules/logging/filters.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/logging/filters.go')
-rw-r--r--modules/logging/filters.go41
1 files changed, 30 insertions, 11 deletions
diff --git a/modules/logging/filters.go b/modules/logging/filters.go
index 8cc84c7..233d5d7 100644
--- a/modules/logging/filters.go
+++ b/modules/logging/filters.go
@@ -25,10 +25,11 @@ import (
"strconv"
"strings"
+ "go.uber.org/zap/zapcore"
+
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
- "go.uber.org/zap/zapcore"
)
func init() {
@@ -81,8 +82,7 @@ func hash(s string) string {
// of the SHA-256 hash of the content. Operates
// on string fields, or on arrays of strings
// where each string is hashed.
-type HashFilter struct {
-}
+type HashFilter struct{}
// CaddyModule returns the Caddy module information.
func (HashFilter) CaddyModule() caddy.ModuleInfo {
@@ -100,12 +100,15 @@ func (f *HashFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Filter filters the input field with the replacement value.
func (f *HashFilter) Filter(in zapcore.Field) zapcore.Field {
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
for i, s := range array {
- array[i] = hash(s)
+ newArray[i] = hash(s)
}
+ in.Interface = newArray
} else {
in.String = hash(in.String)
}
+
return in
}
@@ -219,9 +222,11 @@ func (m *IPMaskFilter) Provision(ctx caddy.Context) error {
// Filter filters the input field.
func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field {
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
for i, s := range array {
- array[i] = m.mask(s)
+ newArray[i] = m.mask(s)
}
+ in.Interface = newArray
} else {
in.String = m.mask(in.String)
}
@@ -368,9 +373,23 @@ func (m *QueryFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Filter filters the input field.
func (m QueryFilter) Filter(in zapcore.Field) zapcore.Field {
- u, err := url.Parse(in.String)
+ if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
+ for i, s := range array {
+ newArray[i] = m.processQueryString(s)
+ }
+ in.Interface = newArray
+ } else {
+ in.String = m.processQueryString(in.String)
+ }
+
+ return in
+}
+
+func (m QueryFilter) processQueryString(s string) string {
+ u, err := url.Parse(s)
if err != nil {
- return in
+ return s
}
q := u.Query()
@@ -392,9 +411,7 @@ func (m QueryFilter) Filter(in zapcore.Field) zapcore.Field {
}
u.RawQuery = q.Encode()
- in.String = u.String()
-
- return in
+ return u.String()
}
type cookieFilterAction struct {
@@ -580,9 +597,11 @@ func (m *RegexpFilter) Provision(ctx caddy.Context) error {
// Filter filters the input field with the replacement value if it matches the regexp.
func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field {
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
for i, s := range array {
- array[i] = f.regexp.ReplaceAllString(s, f.Value)
+ newArray[i] = f.regexp.ReplaceAllString(s, f.Value)
}
+ in.Interface = newArray
} else {
in.String = f.regexp.ReplaceAllString(in.String, f.Value)
}