This commit is contained in:
Martin Polden 2016-04-16 10:45:43 +02:00
parent ed29f49139
commit 7ffaf5e9ac
1 changed files with 6 additions and 9 deletions

View File

@ -78,20 +78,17 @@ func (a *API) EnablePortTesting() {
} }
func ipFromRequest(r *http.Request) (net.IP, error) { func ipFromRequest(r *http.Request) (net.IP, error) {
var host string remoteIP := r.Header.Get("X-Real-IP")
realIP := r.Header.Get("X-Real-IP") if remoteIP == "" {
var err error host, _, err := net.SplitHostPort(r.RemoteAddr)
if realIP != "" {
host = realIP
} else {
host, _, err = net.SplitHostPort(r.RemoteAddr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
remoteIP = host
} }
ip := net.ParseIP(host) ip := net.ParseIP(remoteIP)
if ip == nil { 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 return ip, nil
} }