Patched apple phones not being able to read from jsStreams for some unknown reason
This commit is contained in:
parent
c55ae178b4
commit
1a6a8a36b0
19
main.go
19
main.go
|
@ -187,7 +187,24 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) {
|
||||||
resp.ContentLength = -1
|
resp.ContentLength = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.Body = jsStreams.NewReadableStream(args[0].Get("body"))
|
|
||||||
|
// Safari doesn't support readable streams
|
||||||
|
if strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") {
|
||||||
|
resp.Body = jsStreams.NewReadableStream(args[0].Get("body"))
|
||||||
|
} else {
|
||||||
|
// Read in the body with .arrayBuffer()
|
||||||
|
promise := args[0].Call("bytes")
|
||||||
|
var waitGroup sync.WaitGroup
|
||||||
|
waitGroup.Add(1)
|
||||||
|
promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
|
bytes := make([]byte, args[0].Get("length").Int())
|
||||||
|
js.CopyBytesToGo(bytes, args[0])
|
||||||
|
waitGroup.Done()
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
|
||||||
|
waitGroup.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
// Standard-library compatibility fields
|
// Standard-library compatibility fields
|
||||||
resp.Proto = "HTTP/1.1"
|
resp.Proto = "HTTP/1.1"
|
||||||
|
|
Loading…
Reference in New Issue