1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
823 B
Go

package http
import (
"crypto/tls"
"net/http"
"time"
)
// IsServingHTTP returns true if there appears to be a HTTP or HTTPS server
// running on the given address.
func IsServingHTTP(addr string) bool {
client := http.Client{
Timeout: 2 * time.Second,
}
resp, err := client.Get("http://" + addr)
if err == nil {
resp.Body.Close()
return true
}
// Check for a HTTPS server listening on the same address, using the same URL.
// Don't check the certificate, as we're only interested in whether there's
// a server running.
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = http.Client{
Transport: tr,
Timeout: 2 * time.Second,
}
resp, err = client.Get("https://" + addr + "/status")
if err == nil {
resp.Body.Close()
return true
}
return false
}