[#282] reversed the X-Forwarded-For ips iteration
This commit is contained in:
parent
d4f160d959
commit
3f4f4cf031
|
@ -317,9 +317,10 @@ func realUserIp(r *http.Request, fallbackIp string) string {
|
||||||
if ipsList := r.Header.Get("X-Forwarded-For"); ipsList != "" {
|
if ipsList := r.Header.Get("X-Forwarded-For"); ipsList != "" {
|
||||||
ips := strings.Split(ipsList, ",")
|
ips := strings.Split(ipsList, ",")
|
||||||
// extract the rightmost ip
|
// extract the rightmost ip
|
||||||
for _, ip := range ips {
|
for i := len(ips) - 1; i >= 0; i-- {
|
||||||
if trimmedIp := strings.TrimSpace(ip); trimmedIp != "" {
|
ip := strings.TrimSpace(ips[i])
|
||||||
return trimmedIp
|
if ip != "" {
|
||||||
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue