Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion httpbin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"math/rand"
"mime"
"mime/multipart"
"net"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -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 {
Expand Down
Loading