Skip to content

Commit

Permalink
caddyhttp: Fix panic when request missing ClientIPVarKey (#6040)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Jan 24, 2024
1 parent 750d0b8 commit f5344f8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/caddyhttp/marshalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5344f8

Please sign in to comment.