Fixes IP detection when manually inputting

This commit is contained in:
Mike Raunsbæk 2018-06-15 09:16:50 +02:00
parent b6acdacddd
commit eca444b9cc
1 changed files with 6 additions and 2 deletions

View File

@ -53,17 +53,21 @@ func New(db database.Client) *Server {
}
func ipFromRequest(header string, r *http.Request) (net.IP, error) {
remoteIP := r.Header.Get(header)
if remoteIP == "" && r.URL != nil {
var remoteIP string
if r.URL != nil && remoteIP == "" {
host := filepath.Base(r.URL.Path)
ip := net.ParseIP(host)
if ip != nil {
remoteIP = ip.String()
}
}
if remoteIP == "" {
remoteIP = r.Header.Get(header)
}
if remoteIP == "" {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return nil, err
}
remoteIP = host
}