This commit is contained in:
Martin Polden 2016-04-16 10:45:43 +02:00
parent ed29f49139
commit 7ffaf5e9ac

View File

@ -78,20 +78,17 @@ func (a *API) EnablePortTesting() {
}
func ipFromRequest(r *http.Request) (net.IP, error) {
var host string
realIP := r.Header.Get("X-Real-IP")
var err error
if realIP != "" {
host = realIP
} else {
host, _, err = net.SplitHostPort(r.RemoteAddr)
remoteIP := r.Header.Get("X-Real-IP")
if remoteIP == "" {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return nil, err
}
remoteIP = host
}
ip := net.ParseIP(host)
ip := net.ParseIP(remoteIP)
if ip == nil {
return nil, fmt.Errorf("could not parse IP: %s", host)
return nil, fmt.Errorf("could not parse IP: %s", remoteIP)
}
return ip, nil
}