1
0
mirror of https://github.com/golang/go synced 2024-10-04 06:21:23 -06:00

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
This commit is contained in:
Brad Fitzpatrick 2014-02-24 15:20:45 -08:00
parent c7612f3426
commit 49beb23ba7

View File

@ -30,7 +30,13 @@ import (
// and caches them for reuse by subsequent calls. It uses HTTP proxies // 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 // as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and
// $no_proxy) environment variables. // $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 // DefaultMaxIdleConnsPerHost is the default value of Transport's
// MaxIdleConnsPerHost. // MaxIdleConnsPerHost.