diff --git a/connect/webConn.go b/connect/webConn.go index 0512bfa254ccf7bfa52a8cd0b9e54c363535f6cf..3f899829b1db63521757b29fb66c25c595306b2e 100644 --- a/connect/webConn.go +++ b/connect/webConn.go @@ -189,6 +189,12 @@ func (wc *webConn) isAlive() bool { // IsOnline sends an empty http get request to verify the status of the server func (wc *webConn) IsOnline() (time.Duration, bool) { addr := wc.h.GetAddress() + pingTimeout := wc.h.params.PingTimeout + + return isOnlineHelper(addr, pingTimeout) +} + +func isOnlineHelper(addr string, pingTimeout time.Duration) (time.Duration, bool) { start := time.Now() tr := &http.Transport{ TLSClientConfig: &tls.Config{ @@ -197,9 +203,9 @@ func (wc *webConn) IsOnline() (time.Duration, bool) { } client := http.Client{ Transport: tr, - Timeout: wc.h.params.PingTimeout, + Timeout: pingTimeout, } - target := "http://" + addr + target := "https://" + addr req, err := http.NewRequest("GET", target, nil) if err != nil { jww.WARN.Printf("Failed to initiate request: %+v", err) @@ -219,7 +225,7 @@ func (wc *webConn) IsOnline() (time.Duration, bool) { } // IMPORTANT - enables better HTTP(S) discovery, because many browsers block CORS by default. - req.Header.Add("js.fetch:mode", "no-cors") + //req.Header.Add("js.fetch:mode", "no-cors") jww.TRACE.Printf("(GO request): %+v", req) req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) diff --git a/connect/webConn_test.go b/connect/webConn_test.go index ff8f2f8fbea9519e00eaef1214267532d19af406..0dda5f326f047955cc7453c2a06bbefec88742f3 100644 --- a/connect/webConn_test.go +++ b/connect/webConn_test.go @@ -142,3 +142,9 @@ func Test_checkErrorExceptions(t *testing.T) { } } } + +//func Test_isOnline_actual(t *testing.T) { +// targetAddr := "a98c39d9f9a3b08ddc63d979f69e71c03e76e75353878e3d4b3c2e.xxnode.io:22840" +// _, ok := isOnlineHelper(targetAddr, time.Second*10) +// t.Fatal(ok) +//}