Skip to content

Commit 30b17f4

Browse files
dmitshurgopherbot
authored andcommitted
net/http: only disable Fetch API in tests
The Fetch API was meant to only be disabled in tests. Since wasm_exec.js defines a global 'process' object, it ended up being disabled anywhere that script is used. Make the heuristic stricter so that it's less likely to trigger anywhere but when testing js/wasm using Node.js. For #57613. Fixes #60808. Change-Id: Ief8def802b466ef4faad16daccefcfd72e4398b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/503675 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 65db95d commit 30b17f4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/net/http/roundtrip_js.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"strconv"
14+
"strings"
1415
"syscall/js"
1516
)
1617

@@ -44,11 +45,15 @@ const jsFetchRedirect = "js.fetch:redirect"
4445
// the browser globals.
4546
var jsFetchMissing = js.Global().Get("fetch").IsUndefined()
4647

47-
// jsFetchDisabled will be true if the "process" global is present.
48-
// We use this as an indicator that we're running in Node.js. We
49-
// want to disable the Fetch API in Node.js because it breaks
50-
// our wasm tests. See https://go.dev/issue/57613 for more information.
51-
var jsFetchDisabled = !js.Global().Get("process").IsUndefined()
48+
// jsFetchDisabled controls whether the use of Fetch API is disabled.
49+
// It's set to true when we detect we're running in Node.js, so that
50+
// RoundTrip ends up talking over the same fake network the HTTP servers
51+
// currently use in various tests and examples. See go.dev/issue/57613.
52+
//
53+
// TODO(go.dev/issue/60810): See if it's viable to test the Fetch API
54+
// code path.
55+
var jsFetchDisabled = js.Global().Get("process").Type() == js.TypeObject &&
56+
strings.HasPrefix(js.Global().Get("process").Get("argv0").String(), "node")
5257

5358
// Determine whether the JS runtime supports streaming request bodies.
5459
// Courtesy: https://developer.chrome.com/articles/fetch-streaming-requests/#feature-detection

0 commit comments

Comments
 (0)