status-go/vendor/github.com/anacrolix/missinggo/httptoo/request.go

24 lines
562 B
Go
Raw Normal View History

2022-03-10 09:44:48 +00:00
package httptoo
import (
"net"
"net/http"
"github.com/anacrolix/missinggo"
)
// Request is intended for localhost, either with a localhost name, or
// loopback IP.
func RequestIsForLocalhost(r *http.Request) bool {
hostHost := missinggo.SplitHostMaybePort(r.Host).Host
if ip := net.ParseIP(hostHost); ip != nil {
return ip.IsLoopback()
}
return hostHost == "localhost"
}
// Request originated from a loopback IP.
func RequestIsFromLocalhost(r *http.Request) bool {
return net.ParseIP(missinggo.SplitHostMaybePort(r.RemoteAddr).Host).IsLoopback()
}