Skip to content

Commit a564b4f

Browse files
authored
Merge pull request smallstep#944 from smallstep/herman/tls-wasm-client
Set nil dial context for js/wasm runtime
2 parents 911cec2 + a7dd3a9 commit a564b4f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ca/tls.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net"
1313
"net/http"
1414
"os"
15+
"runtime"
1516
"time"
1617

1718
"github.com/pkg/errors"
@@ -288,10 +289,20 @@ func getDefaultDialer() *net.Dialer {
288289
// transport for HTTP/2.
289290
func getDefaultTransport(tlsConfig *tls.Config) *http.Transport {
290291
var dialContext func(ctx context.Context, network string, addr string) (net.Conn, error)
291-
if mTLSDialContext == nil {
292+
switch {
293+
case runtime.GOOS == "js" && runtime.GOARCH == "wasm":
294+
// when running in js/wasm and using the default dialer context all requests
295+
// performed by the CA client resulted in a "protocol not supported" error.
296+
// By setting the dial context to nil requests will be handled by the browser
297+
// fetch API instead. Currently this will always set the dial context to nil,
298+
// but we could implement some additional logic similar to what's found in
299+
// https://github.com/golang/go/pull/46923/files to support a different dial
300+
// context if it is available, required and expected to work.
301+
dialContext = nil
302+
case mTLSDialContext == nil:
292303
d := getDefaultDialer()
293304
dialContext = d.DialContext
294-
} else {
305+
default:
295306
dialContext = mTLSDialContext()
296307
}
297308
return &http.Transport{

0 commit comments

Comments
 (0)