mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
add explanation 🦀
This commit is contained in:
parent
ffe7ac09d0
commit
2d426b64c3
@ -777,7 +777,7 @@ func (c *Context) RemoteIP() (net.IP, bool) {
|
|||||||
|
|
||||||
func validateHeader(header string) (clientIP string, valid bool) {
|
func validateHeader(header string) (clientIP string, valid bool) {
|
||||||
if header == "" {
|
if header == "" {
|
||||||
return
|
return "", false
|
||||||
}
|
}
|
||||||
items := strings.Split(header, ",")
|
items := strings.Split(header, ",")
|
||||||
for i, ipStr := range items {
|
for i, ipStr := range items {
|
||||||
@ -786,6 +786,10 @@ func validateHeader(header string) (clientIP string, valid bool) {
|
|||||||
if ip == nil {
|
if ip == nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to return the first IP in the list, but,
|
||||||
|
// we should not early return since we need to validate that
|
||||||
|
// the rest of the header is syntactically valid
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
clientIP = ipStr
|
clientIP = ipStr
|
||||||
valid = true
|
valid = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user