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

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)