Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
b80cca5731 | |||
981b39a00b | |||
1a6a8a36b0 | |||
c55ae178b4 |
1 changed files with 26 additions and 4 deletions
30
main.go
30
main.go
|
@ -1,6 +1,7 @@
|
||||||
package jsFetch
|
package jsFetch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
@ -187,7 +188,25 @@ 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
|
||||||
|
println("Trying duck test")
|
||||||
|
if js.Global().Get("ApplePaySession").IsUndefined() {
|
||||||
|
println("Not an apple")
|
||||||
|
resp.Body = jsStreams.NewReadableStream(args[0].Get("body"))
|
||||||
|
} else {
|
||||||
|
// Read in the body with .arrayBuffer()
|
||||||
|
promise := args[0].Call("arrayBuffer")
|
||||||
|
waitGroup.Add(1)
|
||||||
|
promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
|
uint8Array := js.Global().Get("Uint8Array").New(args[0])
|
||||||
|
b := make([]byte, uint8Array.Get("length").Int())
|
||||||
|
js.CopyBytesToGo(b, uint8Array)
|
||||||
|
resp.Body = io.NopCloser(bytes.NewReader(b))
|
||||||
|
waitGroup.Done()
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
// Standard-library compatibility fields
|
// Standard-library compatibility fields
|
||||||
resp.Proto = "HTTP/1.1"
|
resp.Proto = "HTTP/1.1"
|
||||||
|
@ -655,7 +674,8 @@ 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() {
|
// Disable if not https, we don't detect chromium, or we are on 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)
|
||||||
|
@ -671,7 +691,8 @@ 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() {
|
// Disable if not https, we don't detect chromium, or we are on 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)
|
||||||
|
@ -690,7 +711,8 @@ 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() {
|
// Disable if not https, we don't detect chromium, or we are on 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…
Add table
Reference in a new issue