aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>2023-01-27 22:50:54 -0800
committerJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>2023-01-30 18:50:54 +0000
commit4c5d97990e4a39bd3e903f8e318b7234db3ba91f (patch)
treedc1054ca3c5cb20abc63eaaaab9d37856beaf6f6 /src/net/http
parent3875258f971ce534262020c8342e70226b770d95 (diff)
downloadgo-4c5d97990e4a39bd3e903f8e318b7234db3ba91f.tar.xz
net/http: disable fetch on NodeJS
NodeJS 18 introduced support for the fetch API for making HTTP requests. This broke all wasm tests that were relying on NodeJS falling back to the fake network implementation in net_fake.go. Disable the fetch API on NodeJS to get tests passing. Fixes #57613 Change-Id: Icb2cce6d5289d812da798e07366f8ac26b5f82cb Reviewed-on: https://go-review.googlesource.com/c/go/+/463976 Reviewed-by: Evan Phoenix <evan@phx.io> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/roundtrip_js.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go
index 01c0600ba5..21d8df9686 100644
--- a/src/net/http/roundtrip_js.go
+++ b/src/net/http/roundtrip_js.go
@@ -44,6 +44,12 @@ const jsFetchRedirect = "js.fetch:redirect"
// the browser globals.
var jsFetchMissing = js.Global().Get("fetch").IsUndefined()
+// jsFetchDisabled will be true if the "process" global is present.
+// We use this as an indicator that we're running in Node.js. We
+// want to disable the Fetch API in Node.js because it breaks
+// our wasm tests. See https://go.dev/issue/57613 for more information.
+var jsFetchDisabled = !js.Global().Get("process").IsUndefined()
+
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
func (t *Transport) RoundTrip(req *Request) (*Response, error) {
// The Transport has a documented contract that states that if the DialContext or
@@ -52,7 +58,7 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
// though they are deprecated. Therefore, if any of these are set, we should obey
// the contract and dial using the regular round-trip instead. Otherwise, we'll try
// to fall back on the Fetch API, unless it's not available.
- if t.Dial != nil || t.DialContext != nil || t.DialTLS != nil || t.DialTLSContext != nil || jsFetchMissing {
+ if t.Dial != nil || t.DialContext != nil || t.DialTLS != nil || t.DialTLSContext != nil || jsFetchMissing || jsFetchDisabled {
return t.roundTrip(req)
}