mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
Merge c93194e6be33533ae7ef9367a94581be9fbcd0de into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9
This commit is contained in:
commit
4520c2b9bd
8
gin.go
8
gin.go
@ -486,7 +486,13 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
|
||||
items := strings.Split(header, ",")
|
||||
for i := len(items) - 1; i >= 0; i-- {
|
||||
ipStr := strings.TrimSpace(items[i])
|
||||
ip := net.ParseIP(ipStr)
|
||||
// Handle formats like "[::1]:port", "1.2.3.4:port", and "[::1]"
|
||||
host, _, err := net.SplitHostPort(ipStr)
|
||||
if err != nil {
|
||||
// No port present; strip brackets if present (e.g. "[::1]")
|
||||
host = strings.Trim(ipStr, "[]")
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
break
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user