caddyhttp: Fix panic when request missing ClientIPVarKey (#6040)

This commit is contained in:
Francis Lavoie 2024-01-23 19:45:50 -05:00 committed by GitHub
parent 750d0b8331
commit f5344f8cad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -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)