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

Set js header for isonline

parent 9aa8ed7e
No related branches found
No related tags found
2 merge requests!61Hotfix/fix is online,!39Merge release into master
//go:build !js || !wasm
package connect
import "net/http"
func (wc *webConn) addHeaders(header http.Header) http.Header {
return header
}
//go:build js && wasm
package connect
import "net/http"
func (wc *webConn) addHeaders(header http.Header) http.Header {
req.Header.Add("js.fetch:mode", "no-cors")
return header
}
......@@ -191,10 +191,10 @@ func (wc *webConn) IsOnline() (time.Duration, bool) {
addr := wc.h.GetAddress()
pingTimeout := wc.h.params.PingTimeout
return isOnlineHelper(addr, pingTimeout)
return wc.isOnlineHelper(addr, pingTimeout)
}
func isOnlineHelper(addr string, pingTimeout time.Duration) (time.Duration, bool) {
func (wc *webConn) isOnlineHelper(addr string, pingTimeout time.Duration) (time.Duration, bool) {
start := time.Now()
tr := &http.Transport{
TLSClientConfig: &tls.Config{
......@@ -225,7 +225,7 @@ func isOnlineHelper(addr string, pingTimeout time.Duration) (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 = wc.addHeaders(req.Header)
jww.TRACE.Printf("(GO request): %+v", req)
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
......
......@@ -145,6 +145,7 @@ func Test_checkErrorExceptions(t *testing.T) {
//func Test_isOnline_actual(t *testing.T) {
// targetAddr := ".xxnode.io:22840"
// _, ok := isOnlineHelper(targetAddr, time.Second*10)
// wc := webConn{}
// _, ok := wc.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