|
@@ -38,6 +38,7 @@ func (ctx *Context) reset(req *http.Request, res http.ResponseWriter, ps map[str
|
|
|
|
|
|
func (ctx *Context) RealIp() string {
|
|
|
var (
|
|
|
+ s string
|
|
|
pos int
|
|
|
ipaddr string
|
|
|
)
|
|
@@ -48,8 +49,16 @@ func (ctx *Context) RealIp() string {
|
|
|
}
|
|
|
ipaddr, _, _ = net.SplitHostPort(ctx.Request().RemoteAddr)
|
|
|
__end:
|
|
|
- if pos = strings.LastIndexByte(ipaddr, ','); pos > -1 {
|
|
|
- ipaddr = ipaddr[:pos]
|
|
|
+ for {
|
|
|
+ if pos = strings.IndexByte(ipaddr, ','); pos > -1 {
|
|
|
+ s = strings.TrimSpace(ipaddr[:pos])
|
|
|
+ if netip := net.ParseIP(s); netip != nil && !netip.IsPrivate() {
|
|
|
+ return s
|
|
|
+ }
|
|
|
+ ipaddr = ipaddr[pos+1:]
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
return ipaddr
|
|
|
}
|