Skip to content

Commit

Permalink
fix: 🐛 panic when client_ip ctx var is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienyhuel committed Dec 18, 2024
1 parent d7a1ee8 commit 45c1be2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ func processRequest(tx types.Transaction, req *http.Request) (*types.Interruptio
client = req.RemoteAddr[:idx]
cport, _ = strconv.Atoi(req.RemoteAddr[idx+1:])
}
address := caddyhttp.GetVar(req.Context(), caddyhttp.ClientIPVarKey).(string)
clientIp, clientPort, _ := net.SplitHostPort(address)
if clientIp != "" {
client = clientIp
} else if address != "" {
client = address
}
if clientPort != "" {
cport, _ = strconv.Atoi(clientPort)
}
if address, ok := caddyhttp.GetVar(req.Context(), caddyhttp.ClientIPVarKey).(string); ok {
clientIp, clientPort, _ := net.SplitHostPort(address)
if clientIp != "" {
client = clientIp
} else if address != "" {
client = address
}
if clientPort != "" {
cport, _ = strconv.Atoi(clientPort)
}
}

var in *types.Interruption
// There is no socket access in the request object, so we neither know the server client nor port.
Expand Down

0 comments on commit 45c1be2

Please sign in to comment.