Skip to content

Commit e23bc46

Browse files
authored
fix: /ip should not include port number (#212)
1 parent 3855b88 commit e23bc46

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

httpbin/helpers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"math/rand"
1313
"mime"
1414
"mime/multipart"
15+
"net"
1516
"net/http"
1617
"net/url"
1718
"regexp"
@@ -64,7 +65,12 @@ func getClientIP(r *http.Request) string {
6465
}
6566

6667
// Finally, fall back on the actual remote addr from the request.
67-
return r.RemoteAddr
68+
remoteAddr := r.RemoteAddr
69+
if strings.IndexByte(remoteAddr, ':') > 0 {
70+
ip, _, _ := net.SplitHostPort(remoteAddr)
71+
return ip
72+
}
73+
return remoteAddr
6874
}
6975

7076
func getURL(r *http.Request) *url.URL {

0 commit comments

Comments
 (0)