30 lines
759 B
Go
30 lines
759 B
Go
package scanner
|
|
|
|
import (
|
|
x509 "crypto/x509"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
func CheckHTTP200(ctx Context, url, basicAuthUsername string, basicAuthPassword string) (bool, string) {
|
|
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
|
if err != nil {
|
|
return false, err.Error()
|
|
}
|
|
req.SetBasicAuth(basicAuthUsername, basicAuthPassword)
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
var tlsCertErr x509.CertificateInvalidError
|
|
if errors.As(err, &tlsCertErr) {
|
|
return false, "tls: failed to verify certificate: x509: CertificateInvalidError (details truncated)"
|
|
}
|
|
return false, err.Error()
|
|
}
|
|
|
|
// if code is 200-299
|
|
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
|
|
return true, resp.Status
|
|
}
|
|
|
|
return false, resp.Status
|
|
}
|