From 103f84ce299d4ed7c764d463de694f9a316dc9d0 Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Wed, 4 Jan 2023 18:23:09 -0500
Subject: [PATCH] Use https for isonline

---
 connect/webConn.go      | 12 +++++++++---
 connect/webConn_test.go |  6 ++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/connect/webConn.go b/connect/webConn.go
index 0512bfa..3f89982 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 ff8f2f8..0dda5f3 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)
+//}
-- 
GitLab