Skip to content

Commit

Permalink
Apparently, it’s possible to receive ipv6 without port.
Browse files Browse the repository at this point in the history
  • Loading branch information
didip committed Nov 18, 2017
1 parent f2c85b5 commit b65680a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libstring/libstring.go
Expand Up @@ -24,7 +24,12 @@ func RemoteIP(ipLookups []string, forwardedForIndexFromBehind int, r *http.Reque

for _, lookup := range ipLookups {
if lookup == "RemoteAddr" {
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
// 1. Cover the basic use cases for both ipv4 and ipv6
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
// 2. Upon error, just return the remote addr.
return r.RemoteAddr
}
return ip
}
if lookup == "X-Forwarded-For" && forwardedFor != "" {
Expand Down

0 comments on commit b65680a

Please sign in to comment.