From 1a6a8a36b0920976f5ddd5905a56d2896bbccd24 Mon Sep 17 00:00:00 2001 From: arzumify Date: Wed, 5 Feb 2025 16:47:31 +0000 Subject: [PATCH] Patched apple phones not being able to read from jsStreams for some unknown reason --- main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 8642fee..c1b917a 100644 --- a/main.go +++ b/main.go @@ -187,7 +187,24 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { 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 resp.Proto = "HTTP/1.1"