From 49beb23ba73eab22c470e68cac87d51a0d12d97b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Feb 2014 15:20:45 -0800 Subject: [PATCH] net/http: use TCP Keep-Alives on DefaultTransport's connections Update #3362 Also set a 30 second timeout, instead of relying on the operating system's timeout, which if often but not always 3 minutes. LGTM=crawshaw R=rsc, crawshaw CC=golang-codereviews https://golang.org/cl/68330046 --- src/pkg/net/http/transport.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pkg/net/http/transport.go b/src/pkg/net/http/transport.go index 5655d704f7..cdad339a03 100644 --- a/src/pkg/net/http/transport.go +++ b/src/pkg/net/http/transport.go @@ -30,7 +30,13 @@ import ( // 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} +var DefaultTransport RoundTripper = &Transport{ + Proxy: ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, +} // DefaultMaxIdleConnsPerHost is the default value of Transport's // MaxIdleConnsPerHost. -- 2.48.1