diff --git a/httpbin/helpers.go b/httpbin/helpers.go index d46c33a..d1ddf97 100644 --- a/httpbin/helpers.go +++ b/httpbin/helpers.go @@ -12,6 +12,7 @@ import ( "math/rand" "mime" "mime/multipart" + "net" "net/http" "net/url" "regexp" @@ -64,7 +65,12 @@ func getClientIP(r *http.Request) string { } // Finally, fall back on the actual remote addr from the request. - return r.RemoteAddr + remoteAddr := r.RemoteAddr + if strings.IndexByte(remoteAddr, ':') > 0 { + ip, _, _ := net.SplitHostPort(remoteAddr) + return ip + } + return remoteAddr } func getURL(r *http.Request) *url.URL {