diff --git a/main.go b/main.go index 9dc3a3f..109b571 100644 --- a/main.go +++ b/main.go @@ -80,10 +80,18 @@ func getIPCountry(ip string) string { func handleRequest(w http.ResponseWriter, r *http.Request) { sourceIP := func() string { - if ip := r.Header.Get("X-Forwarded-For"); ip != "" { + if ip := r.Header.Get("X-Forwarded-For"); ip != "" { return strings.Split(ip, ",")[0] } - return strings.Split(r.RemoteAddr, ":")[0] + + host, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + errorText := fmt.Sprintf("Unable to parse remote address: %v", err) + log.Printf(errorText) + return errorText + } + + return host }() isHeadless := strings.HasPrefix(r.Header.Get("User-Agent"), "curl/")