Skip to content
Snippets Groups Projects
Commit 103f84ce authored by Jonah Husson's avatar Jonah Husson
Browse files

Use https for isonline

parent 11f1f406
No related branches found
No related tags found
2 merge requests!61Hotfix/fix is online,!39Merge release into master
...@@ -189,6 +189,12 @@ func (wc *webConn) isAlive() bool { ...@@ -189,6 +189,12 @@ func (wc *webConn) isAlive() bool {
// IsOnline sends an empty http get request to verify the status of the server // IsOnline sends an empty http get request to verify the status of the server
func (wc *webConn) IsOnline() (time.Duration, bool) { func (wc *webConn) IsOnline() (time.Duration, bool) {
addr := wc.h.GetAddress() 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() start := time.Now()
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
...@@ -197,9 +203,9 @@ func (wc *webConn) IsOnline() (time.Duration, bool) { ...@@ -197,9 +203,9 @@ func (wc *webConn) IsOnline() (time.Duration, bool) {
} }
client := http.Client{ client := http.Client{
Transport: tr, Transport: tr,
Timeout: wc.h.params.PingTimeout, Timeout: pingTimeout,
} }
target := "http://" + addr target := "https://" + addr
req, err := http.NewRequest("GET", target, nil) req, err := http.NewRequest("GET", target, nil)
if err != nil { if err != nil {
jww.WARN.Printf("Failed to initiate request: %+v", err) jww.WARN.Printf("Failed to initiate request: %+v", err)
...@@ -219,7 +225,7 @@ func (wc *webConn) IsOnline() (time.Duration, bool) { ...@@ -219,7 +225,7 @@ func (wc *webConn) IsOnline() (time.Duration, bool) {
} }
// IMPORTANT - enables better HTTP(S) discovery, because many browsers block CORS by default. // 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) jww.TRACE.Printf("(GO request): %+v", req)
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
......
...@@ -142,3 +142,9 @@ func Test_checkErrorExceptions(t *testing.T) { ...@@ -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)
//}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment