diff --git a/main.go b/main.go index 4c2794b..7e6e3d7 100644 --- a/main.go +++ b/main.go @@ -655,7 +655,14 @@ func Get(url string) (response *Response, err error) { if err != nil { return } + if !strings.HasPrefix(url, "https://") && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + } response, err = Fetch.Do(request) + if !request.DisableStreamedClient && err != nil && err.Error() == "Failed to fetch" && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + response, err = Fetch.Do(request) + } return } @@ -664,8 +671,15 @@ func Post(url string, contentType string, body io.Reader) (response *Response, e if err != nil { return } + if !strings.HasPrefix(url, "https://") && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + } request.Header.Add("Content-Type", contentType) response, err = Fetch.Do(request) + if !request.DisableStreamedClient && err != nil && err.Error() == "Failed to fetch" && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + response, err = Fetch.Do(request) + } return } @@ -676,7 +690,14 @@ func PostForm(url string, data url.Values) (response *Response, err error) { return } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") + if !strings.HasPrefix(url, "https://") && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + } response, err = Fetch.Do(request) + if !request.DisableStreamedClient && err != nil && err.Error() == "Failed to fetch" && !js.Global().Get("chrome").IsUndefined() { + request.DisableStreamedClient = true + response, err = Fetch.Do(request) + } return } diff --git a/tests/client/main.go b/tests/client/main.go index 0ad2def..87d7981 100644 --- a/tests/client/main.go +++ b/tests/client/main.go @@ -38,7 +38,7 @@ func tryHead(url string) error { } func tryPost(url string, message string) error { - response, err := jsFetch.Post(url, strings.NewReader(message)) + response, err := jsFetch.Post(url, "text/plain", strings.NewReader(message)) if err != nil { return err }