Patched apple phones not being able to read from jsStreams for some unknown reason (2)
This commit is contained in:
parent
1a6a8a36b0
commit
981b39a00b
14
main.go
14
main.go
|
@ -1,6 +1,7 @@
|
||||||
package jsFetch
|
package jsFetch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
@ -189,7 +190,7 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safari doesn't support readable streams
|
// Safari doesn't support readable streams
|
||||||
if strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") {
|
if !js.Global().Get("ApplePaySession").IsUndefined() {
|
||||||
resp.Body = jsStreams.NewReadableStream(args[0].Get("body"))
|
resp.Body = jsStreams.NewReadableStream(args[0].Get("body"))
|
||||||
} else {
|
} else {
|
||||||
// Read in the body with .arrayBuffer()
|
// Read in the body with .arrayBuffer()
|
||||||
|
@ -197,8 +198,9 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) {
|
||||||
var waitGroup sync.WaitGroup
|
var waitGroup sync.WaitGroup
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
bytes := make([]byte, args[0].Get("length").Int())
|
b := make([]byte, args[0].Get("length").Int())
|
||||||
js.CopyBytesToGo(bytes, args[0])
|
js.CopyBytesToGo(b, args[0])
|
||||||
|
resp.Body = io.NopCloser(bytes.NewReader(b))
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
@ -673,7 +675,7 @@ func Get(url string) (response *Response, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Disable if not https, we don't detect chromium, or we are on safari
|
// Disable if not https, we don't detect chromium, or we are on safari
|
||||||
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") {
|
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() {
|
||||||
request.DisableStreamedClient = true
|
request.DisableStreamedClient = true
|
||||||
}
|
}
|
||||||
response, err = Fetch.Do(request)
|
response, err = Fetch.Do(request)
|
||||||
|
@ -690,7 +692,7 @@ func Post(url string, contentType string, body io.Reader) (response *Response, e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Disable if not https, we don't detect chromium, or we are on safari
|
// Disable if not https, we don't detect chromium, or we are on safari
|
||||||
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") {
|
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() {
|
||||||
request.DisableStreamedClient = true
|
request.DisableStreamedClient = true
|
||||||
}
|
}
|
||||||
request.Header.Add("Content-Type", contentType)
|
request.Header.Add("Content-Type", contentType)
|
||||||
|
@ -710,7 +712,7 @@ func PostForm(url string, data url.Values) (response *Response, err error) {
|
||||||
}
|
}
|
||||||
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
// Disable if not https, we don't detect chromium, or we are on safari
|
// Disable if not https, we don't detect chromium, or we are on safari
|
||||||
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") {
|
if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() {
|
||||||
request.DisableStreamedClient = true
|
request.DisableStreamedClient = true
|
||||||
}
|
}
|
||||||
response, err = Fetch.Do(request)
|
response, err = Fetch.Do(request)
|
||||||
|
|
Loading…
Reference in New Issue