Fix logging of IPv6 addresses with scope

This commit is contained in:
Eric Lindvall 2022-01-19 19:21:46 -08:00
parent 1b28e2b030
commit df1c72fe41
1 changed files with 2 additions and 1 deletions

View File

@ -760,9 +760,10 @@ func (c *Context) ClientIP() string {
// It also checks if the remoteIP is a trusted proxy or not. // It also checks if the remoteIP is a trusted proxy or not.
// In order to perform this validation, it will see if the IP is contained within at least one of the CIDR blocks // In order to perform this validation, it will see if the IP is contained within at least one of the CIDR blocks
// defined by Engine.SetTrustedProxies() // defined by Engine.SetTrustedProxies()
// If the IP could not be parsed (because, for instance, it is an ipv6 address with a scope), it will return the remote IP as-is.
remoteIP := net.ParseIP(c.RemoteIP()) remoteIP := net.ParseIP(c.RemoteIP())
if remoteIP == nil { if remoteIP == nil {
return "" return c.RemoteIP()
} }
trusted := c.engine.isTrustedProxy(remoteIP) trusted := c.engine.isTrustedProxy(remoteIP)