Skip to content

Commit 220552f

Browse files
johanbrandhorstbradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 16796af commit 220552f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/net/http/roundtrip_js.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"io/ioutil"
14-
"os"
1514
"strconv"
16-
"strings"
1715
"syscall/js"
1816
)
1917

@@ -43,9 +41,11 @@ const jsFetchCreds = "js.fetch:credentials"
4341
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
4442
const jsFetchRedirect = "js.fetch:redirect"
4543

44+
var useFakeNetwork = js.Global().Get("fetch") == js.Undefined()
45+
4646
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
4747
func (t *Transport) RoundTrip(req *Request) (*Response, error) {
48-
if useFakeNetwork() {
48+
if useFakeNetwork {
4949
return t.roundTrip(req)
5050
}
5151

@@ -182,12 +182,6 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
182182

183183
var errClosed = errors.New("net/http: reader is closed")
184184

185-
// useFakeNetwork is used to determine whether the request is made
186-
// by a test and should be made to use the fake in-memory network.
187-
func useFakeNetwork() bool {
188-
return len(os.Args) > 0 && strings.HasSuffix(os.Args[0], ".test")
189-
}
190-
191185
// streamReader implements an io.ReadCloser wrapper for ReadableStream.
192186
// See https://fetch.spec.whatwg.org/#readablestream for more information.
193187
type streamReader struct {

0 commit comments

Comments
 (0)