mirror of https://github.com/mpolden/echoip
Fixes IP detection when manually inputting
This commit is contained in:
parent
b6acdacddd
commit
eca444b9cc
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue