mirror of
https://github.com/gin-gonic/gin.git
synced 2026-12-02 09:16:24 +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, ",")
|
items := strings.Split(header, ",")
|
||||||
for i := len(items) - 1; i >= 0; i-- {
|
for i := len(items) - 1; i >= 0; i-- {
|
||||||
ipStr := strings.TrimSpace(items[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 {
|
if ip == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user