From ad63fc05105799ec7f6324daf641e80a3f605e8b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 7 Nov 2021 13:49:55 -0800 Subject: [PATCH] control/controlclient: make js/wasm work with Go 1.18+ Updates #3157 Change-Id: I2d67e582842ab3638d720bb5db4701b878ad4473 Signed-off-by: Brad Fitzpatrick --- control/controlclient/direct.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 67446b03b..ce15486cc 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -146,6 +146,13 @@ func NewDirect(opts Options) (*Direct, error) { } httpc := opts.HTTPTestClient + if httpc == nil && runtime.GOOS == "js" { + // In js/wasm, net/http.Transport (as of Go 1.18) will + // only use the browser's Fetch API if you're using + // the DefaultClient (or a client without dial hooks + // etc set). + httpc = http.DefaultClient + } if httpc == nil { dnsCache := &dnscache.Resolver{ Forward: dnscache.Get().Forward, // use default cache's forwarder