From 23ee196fce0ded06a2f5d0a6f8306d5ca79aead2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 29 Jun 2021 11:56:44 +0100 Subject: [PATCH] Don't specify DialContext by default on js/wasm for DefaultTransport --- AUTHORS | 1 + CONTRIBUTORS | 1 + src/net/http/transport.go | 18 -------------- src/net/http/transport_default_js.go | 26 +++++++++++++++++++++ src/net/http/transport_default_other.go | 31 +++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 src/net/http/transport_default_js.go create mode 100644 src/net/http/transport_default_other.go diff --git a/AUTHORS b/AUTHORS index 95d3158d20..1edabd3acd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1015,6 +1015,7 @@ Nathan Youngman Nathaniel Cook Naveen Kumar Sangi Neelesh Chandola +Neil Alexander Neil Lyons Netflix, Inc. Neuman Vong diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ee50a4c049..027710eb7b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1812,6 +1812,7 @@ Naveen Kumar Sangi Neeilan Selvalingam Neelesh Chandola Nehal J Wani +Neil Alexander Neil Lyons Neuman Vong Neven Sajko diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 47cb992a50..c0cc8a528f 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -35,24 +35,6 @@ import ( "golang.org/x/net/http/httpproxy" ) -// DefaultTransport is the default implementation of Transport and is -// used by DefaultClient. It establishes network connections as needed -// and caches them for reuse by subsequent calls. It uses HTTP proxies -// as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and -// $no_proxy) environment variables. -var DefaultTransport RoundTripper = &Transport{ - Proxy: ProxyFromEnvironment, - DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).DialContext, - ForceAttemptHTTP2: true, - MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 1 * time.Second, -} - // DefaultMaxIdleConnsPerHost is the default value of Transport's // MaxIdleConnsPerHost. const DefaultMaxIdleConnsPerHost = 2 diff --git a/src/net/http/transport_default_js.go b/src/net/http/transport_default_js.go new file mode 100644 index 0000000000..0a2899c0e6 --- /dev/null +++ b/src/net/http/transport_default_js.go @@ -0,0 +1,26 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build js && wasm +// +build js,wasm + +package http + +import ( + "time" +) + +// DefaultTransport is the default implementation of Transport and is +// used by DefaultClient. It uses HTTP proxies as directed by the +// $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) environment +// variables. No default dialer is specified as the Fetch API will be +// used in RoundTrip if not specified. +var DefaultTransport RoundTripper = &Transport{ + Proxy: ProxyFromEnvironment, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, +} diff --git a/src/net/http/transport_default_other.go b/src/net/http/transport_default_other.go new file mode 100644 index 0000000000..4b6b7b47ea --- /dev/null +++ b/src/net/http/transport_default_other.go @@ -0,0 +1,31 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !js || !wasm +// +build !js !wasm + +package http + +import ( + "net" + "time" +) + +// DefaultTransport is the default implementation of Transport and is +// used by DefaultClient. It establishes network connections as needed +// and caches them for reuse by subsequent calls. It uses HTTP proxies +// as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and +// $no_proxy) environment variables. +var DefaultTransport RoundTripper = &Transport{ + Proxy: ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, +}