From 786402ca7ebc03b1ded92d9c236c33e46b0eef49 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 31 Aug 2018 18:51:45 +0800 Subject: [PATCH] =?UTF-8?q?ghttp.Request=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=94=A8=E6=88=B7=E7=9C=9F=E5=AE=9EIP=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/ghttp/ghttp_request.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/g/net/ghttp/ghttp_request.go b/g/net/ghttp/ghttp_request.go index 0ec7cabc6..a7ea33af5 100644 --- a/g/net/ghttp/ghttp_request.go +++ b/g/net/ghttp/ghttp_request.go @@ -168,11 +168,13 @@ func (r *Request) IsAjaxRequest() bool { func (r *Request) GetClientIp() string { ip := r.clientIp.Val() if len(ip) == 0 { - array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr) - if len(array) > 1 { - ip = array[1] - } else { - ip = r.RemoteAddr + if ip = r.Header.Get("X-Real-IP"); ip == "" { + array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr) + if len(array) > 1 { + ip = array[1] + } else { + ip = r.RemoteAddr + } } r.clientIp.Set(ip) }