aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohan Brandhorst <johan.brandhorst@gmail.com>2019-05-28 21:51:54 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2019-05-30 17:59:57 +0000
commit220552f6624f530079b81ba866cd1ffb2f240370 (patch)
treefae83bb72a6c85d5ded8e2468d3c3540245bf69e /src
parent16796afc35de049a89da42efaad1593c26a96392 (diff)
downloadgo-220552f6624f530079b81ba866cd1ffb2f240370.tar.xz
net/http: enable WASM fetch where supported
The existing check was introduced to allow tests to pass on WASM without an environment where the fetch RoundTripper could run. However, the check now prohibits the use of the Fetch RoundTripper in all WASM tests, even where the RoundTripper could run. The new change should only disable the RoundTripper when used in an environment without fetch. Fixes #32289 Change-Id: I30d2e0dbcb0e64d4b1a46b583f7e984c2a57d5e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/179118 Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/net/http/roundtrip_js.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go
index 9a4c369d66..6331351a83 100644
--- a/src/net/http/roundtrip_js.go
+++ b/src/net/http/roundtrip_js.go
@@ -11,9 +11,7 @@ import (
"fmt"
"io"
"io/ioutil"
- "os"
"strconv"
- "strings"
"syscall/js"
)
@@ -43,9 +41,11 @@ const jsFetchCreds = "js.fetch:credentials"
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
const jsFetchRedirect = "js.fetch:redirect"
+var useFakeNetwork = js.Global().Get("fetch") == js.Undefined()
+
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
func (t *Transport) RoundTrip(req *Request) (*Response, error) {
- if useFakeNetwork() {
+ if useFakeNetwork {
return t.roundTrip(req)
}
@@ -182,12 +182,6 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
var errClosed = errors.New("net/http: reader is closed")
-// useFakeNetwork is used to determine whether the request is made
-// by a test and should be made to use the fake in-memory network.
-func useFakeNetwork() bool {
- return len(os.Args) > 0 && strings.HasSuffix(os.Args[0], ".test")
-}
-
// streamReader implements an io.ReadCloser wrapper for ReadableStream.
// See https://fetch.spec.whatwg.org/#readablestream for more information.
type streamReader struct {