Skip to content

Commit

Permalink
Simplify REALIP method (labstack#1193)
Browse files Browse the repository at this point in the history
* Simplify REALIP method

* Remove alloc
  • Loading branch information
ribice authored and vishr committed Sep 19, 2018
1 parent c185ebd commit a2d4cb9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a2d4cb9

Please sign in to comment.