YTSFlix_Go/vendor/github.com/anacrolix/missinggo/httptoo/request.go

24 lines
562 B
Go
Raw Normal View History

2018-11-04 14:58:15 +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()
}