mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-22 02:43:36 +08:00
Merge c93194e6be33533ae7ef9367a94581be9fbcd0de into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646
This commit is contained in:
commit
adc19dd39e
8
gin.go
8
gin.go
@ -509,7 +509,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