File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import (
26
26
27
27
"github.com/caddyserver/caddy/v2"
28
28
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
29
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
29
30
"go.uber.org/zap/zapcore"
30
31
)
31
32
@@ -456,7 +457,13 @@ func (m *CookieFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
456
457
457
458
// Filter filters the input field.
458
459
func (m CookieFilter ) Filter (in zapcore.Field ) zapcore.Field {
459
- originRequest := http.Request {Header : http.Header {"Cookie" : []string {in .String }}}
460
+ cookiesSlice , ok := in .Interface .(caddyhttp.LoggableStringArray )
461
+ if ! ok {
462
+ return in
463
+ }
464
+
465
+ // using a dummy Request to make use of the Cookies() function to parse it
466
+ originRequest := http.Request {Header : http.Header {"Cookie" : cookiesSlice }}
460
467
cookies := originRequest .Cookies ()
461
468
transformedRequest := http.Request {Header : make (http.Header )}
462
469
@@ -486,7 +493,7 @@ OUTER:
486
493
transformedRequest .AddCookie (c )
487
494
}
488
495
489
- in .String = transformedRequest .Header . Get ( "Cookie" )
496
+ in .Interface = caddyhttp . LoggableStringArray ( transformedRequest .Header [ "Cookie" ] )
490
497
491
498
return in
492
499
}
Original file line number Diff line number Diff line change 4
4
"testing"
5
5
6
6
"github.com/caddyserver/caddy/v2"
7
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
7
8
"go.uber.org/zap/zapcore"
8
9
)
9
10
@@ -49,8 +50,14 @@ func TestCookieFilter(t *testing.T) {
49
50
{hashAction , "hash" , "" },
50
51
}}
51
52
52
- out := f .Filter (zapcore.Field {String : "foo=a; foo=b; bar=c; bar=d; baz=e; hash=hashed" })
53
- if out .String != "foo=REDACTED; foo=REDACTED; baz=e; hash=1a06df82" {
53
+ out := f .Filter (zapcore.Field {Interface : caddyhttp.LoggableStringArray {
54
+ "foo=a; foo=b; bar=c; bar=d; baz=e; hash=hashed" ,
55
+ }})
56
+ outval := out .Interface .(caddyhttp.LoggableStringArray )
57
+ expected := caddyhttp.LoggableStringArray {
58
+ "foo=REDACTED; foo=REDACTED; baz=e; hash=1a06df82" ,
59
+ }
60
+ if outval [0 ] != expected [0 ] {
54
61
t .Fatalf ("cookies have not been filtered: %s" , out .String )
55
62
}
56
63
}
You can’t perform that action at this time.
0 commit comments