mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue #1615
This commit is contained in:
@ -184,30 +184,31 @@ func (r *Request) IsAjaxRequest() bool {
|
||||
// GetClientIp returns the client ip of this request without port.
|
||||
// Note that this ip address might be modified by client header.
|
||||
func (r *Request) GetClientIp() string {
|
||||
if len(r.clientIp) == 0 {
|
||||
realIps := r.Header.Get("X-Forwarded-For")
|
||||
if realIps != "" && len(realIps) != 0 && !strings.EqualFold("unknown", realIps) {
|
||||
ipArray := strings.Split(realIps, ",")
|
||||
r.clientIp = ipArray[0]
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.Header.Get("Proxy-Client-IP")
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.Header.Get("WL-Proxy-Client-IP")
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.Header.Get("HTTP_CLIENT_IP")
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.Header.Get("HTTP_X_FORWARDED_FOR")
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.Header.Get("X-Real-IP")
|
||||
}
|
||||
if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
|
||||
r.clientIp = r.GetRemoteIp()
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
return r.clientIp
|
||||
}
|
||||
realIps := r.Header.Get("X-Forwarded-For")
|
||||
if realIps != "" && len(realIps) != 0 && !strings.EqualFold("unknown", realIps) {
|
||||
ipArray := strings.Split(realIps, ",")
|
||||
r.clientIp = ipArray[0]
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.Header.Get("Proxy-Client-IP")
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.Header.Get("WL-Proxy-Client-IP")
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.Header.Get("HTTP_CLIENT_IP")
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.Header.Get("HTTP_X_FORWARDED_FOR")
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.Header.Get("X-Real-IP")
|
||||
}
|
||||
if r.clientIp == "" {
|
||||
r.clientIp = r.GetRemoteIp()
|
||||
}
|
||||
return r.clientIp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user