Fixed tests, made it try to retry without streamed uploads on chromium if using Get() or Post()

This commit is contained in:
Tracker-Friendly 2024-11-13 17:53:08 +00:00
parent a060c22222
commit f5b3297d9d
2 changed files with 22 additions and 1 deletions

21
main.go
View File

@ -655,7 +655,14 @@ func Get(url string) (response *Response, err error) {
if err != nil { if err != nil {
return return
} }
if !strings.HasPrefix(url, "https://") && !js.Global().Get("chrome").IsUndefined() {
request.DisableStreamedClient = true
}
response, err = Fetch.Do(request) 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 return
} }
@ -664,8 +671,15 @@ func Post(url string, contentType string, body io.Reader) (response *Response, e
if err != nil { if err != nil {
return return
} }
if !strings.HasPrefix(url, "https://") && !js.Global().Get("chrome").IsUndefined() {
request.DisableStreamedClient = true
}
request.Header.Add("Content-Type", contentType) request.Header.Add("Content-Type", contentType)
response, err = Fetch.Do(request) 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 return
} }
@ -676,7 +690,14 @@ func PostForm(url string, data url.Values) (response *Response, err error) {
return return
} }
request.Header.Add("Content-Type", "application/x-www-form-urlencoded") 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) 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 return
} }

View File

@ -38,7 +38,7 @@ func tryHead(url string) error {
} }
func tryPost(url string, message 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 { if err != nil {
return err return err
} }