diff options
author | Francis Lavoie <[email protected]> | 2024-01-23 19:45:50 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-01-24 00:45:50 +0000 |
commit | f5344f8caddee53cebe249712ba7803e22abf9f1 (patch) | |
tree | eecf9f34a9b615a25500b60d1c34d3fcacdf4cef /modules | |
parent | 750d0b83319ac0ea6b7f057b8270c19404c3d6fa (diff) | |
download | caddy-f5344f8caddee53cebe249712ba7803e22abf9f1.tar.gz caddy-f5344f8caddee53cebe249712ba7803e22abf9f1.zip |
caddyhttp: Fix panic when request missing ClientIPVarKey (#6040)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/marshalers.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/modules/caddyhttp/marshalers.go b/modules/caddyhttp/marshalers.go index 9a955e3b6..8f4472a27 100644 --- a/modules/caddyhttp/marshalers.go +++ b/modules/caddyhttp/marshalers.go @@ -40,7 +40,9 @@ func (r LoggableHTTPRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("remote_ip", ip) enc.AddString("remote_port", port) - enc.AddString("client_ip", GetVar(r.Context(), ClientIPVarKey).(string)) + if ip, ok := GetVar(r.Context(), ClientIPVarKey).(string); ok { + enc.AddString("client_ip", ip) + } enc.AddString("proto", r.Proto) enc.AddString("method", r.Method) enc.AddString("host", r.Host) |