|
|
|
@ -22,8 +22,11 @@ import (
|
|
|
|
|
"errors"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var UserAgent = "LenMonitor/unknown"
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
ErrFailedConnect = errors.New("tester: failed to connect to server via HTTP or HTTPS")
|
|
|
|
|
ErrNot200 = errors.New("tester: HTTP server response code is different from 200 when requesting HTTP and HTTPS")
|
|
|
|
@ -69,10 +72,18 @@ func getHttpAndHttps(domain string, path string) (*http.Response, bool, bool, bo
|
|
|
|
|
// Disable redirect
|
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
|
|
|
return http.ErrUseLastResponse
|
|
|
|
|
}}
|
|
|
|
|
},
|
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try HTTP
|
|
|
|
|
respHttp, err := client.Get("http://" + domain + path)
|
|
|
|
|
reqHttp, err := http.NewRequest("GET", "http://"+domain+path, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, domainIsIP, httpSupport, httpsSupport, httpToHttpsRedirect, false, err
|
|
|
|
|
}
|
|
|
|
|
reqHttp.Header.Set("User-Agent", UserAgent)
|
|
|
|
|
|
|
|
|
|
respHttp, err := client.Do(reqHttp)
|
|
|
|
|
if err != nil {
|
|
|
|
|
httpSupport = false
|
|
|
|
|
|
|
|
|
@ -86,7 +97,13 @@ func getHttpAndHttps(domain string, path string) (*http.Response, bool, bool, bo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try HTTPS
|
|
|
|
|
respHttps, err := client.Get("https://" + domain + path)
|
|
|
|
|
reqHttps, err := http.NewRequest("GET", "https://"+domain+path, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, domainIsIP, httpSupport, httpsSupport, httpToHttpsRedirect, false, err
|
|
|
|
|
}
|
|
|
|
|
reqHttps.Header.Set("User-Agent", UserAgent)
|
|
|
|
|
|
|
|
|
|
respHttps, err := client.Do(reqHttps)
|
|
|
|
|
if err != nil {
|
|
|
|
|
httpsSupport = false
|
|
|
|
|
|
|
|
|
|