Commit 220552f6 authored by Johan Brandhorst's avatar Johan Brandhorst Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 16796afc
...@@ -11,9 +11,7 @@ import ( ...@@ -11,9 +11,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os"
"strconv" "strconv"
"strings"
"syscall/js" "syscall/js"
) )
...@@ -43,9 +41,11 @@ const jsFetchCreds = "js.fetch:credentials" ...@@ -43,9 +41,11 @@ const jsFetchCreds = "js.fetch:credentials"
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters // Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
const jsFetchRedirect = "js.fetch:redirect" const jsFetchRedirect = "js.fetch:redirect"
var useFakeNetwork = js.Global().Get("fetch") == js.Undefined()
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API. // RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
func (t *Transport) RoundTrip(req *Request) (*Response, error) { func (t *Transport) RoundTrip(req *Request) (*Response, error) {
if useFakeNetwork() { if useFakeNetwork {
return t.roundTrip(req) return t.roundTrip(req)
} }
...@@ -182,12 +182,6 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { ...@@ -182,12 +182,6 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
var errClosed = errors.New("net/http: reader is closed") 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. // streamReader implements an io.ReadCloser wrapper for ReadableStream.
// See https://fetch.spec.whatwg.org/#readablestream for more information. // See https://fetch.spec.whatwg.org/#readablestream for more information.
type streamReader struct { type streamReader struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment