1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Simplify REALIP method (#1193)

* Simplify REALIP method

* Remove alloc
This commit is contained in:
Emir Ribić 2018-09-19 19:18:50 +02:00 committed by Vishal Rana
parent c185ebd0de
commit a2d4cb9c7a

View File

@ -256,14 +256,13 @@ func (c *context) Scheme() string {
}
func (c *context) RealIP() string {
ra := c.request.RemoteAddr
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
ra = strings.Split(ip, ", ")[0]
} else if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
ra = ip
} else {
ra, _, _ = net.SplitHostPort(ra)
return strings.Split(ip, ", ")[0]
}
if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
return ip
}
ra, _, _ := net.SplitHostPort(c.request.RemoteAddr)
return ra
}