From 50850a7485adf0528b7cf25678851d666cdbbc10 Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Tue, 10 Jun 2025 11:00:37 -0400 Subject: [PATCH 1/2] fix: `/ip` should not include port number --- httpbin/helpers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/httpbin/helpers.go b/httpbin/helpers.go index d46c33a..97a190b 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,8 @@ func getClientIP(r *http.Request) string { } // Finally, fall back on the actual remote addr from the request. - return r.RemoteAddr + ip, _, _ := net.SplitHostPort(r.RemoteAddr) + return ip } func getURL(r *http.Request) *url.URL { From 0bde92b81dceb0e218edc2ef35ec59c0cdaa1e68 Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Tue, 10 Jun 2025 23:21:47 -0400 Subject: [PATCH 2/2] fix fix (needs test) --- httpbin/helpers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/httpbin/helpers.go b/httpbin/helpers.go index 97a190b..d1ddf97 100644 --- a/httpbin/helpers.go +++ b/httpbin/helpers.go @@ -65,8 +65,12 @@ func getClientIP(r *http.Request) string { } // Finally, fall back on the actual remote addr from the request. - ip, _, _ := net.SplitHostPort(r.RemoteAddr) - return ip + remoteAddr := r.RemoteAddr + if strings.IndexByte(remoteAddr, ':') > 0 { + ip, _, _ := net.SplitHostPort(remoteAddr) + return ip + } + return remoteAddr } func getURL(r *http.Request) *url.URL {