Fix http2 support and KeepAlive
@@ -45,7 +45,10 @@ func getTransport(conf *TransportConfig) *http.Transport {
tlsConf.ServerName = conf.Hostname
}
- d := &net.Dialer{Timeout: conf.ConnectTimeout}
+ d := &net.Dialer{
+ KeepAlive: 60 * time.Second,
+ Timeout: conf.ConnectTimeout,
+ }
var proxyFunc func(req *http.Request) (*url.URL, error)
if conf.Proxy != "" {
@@ -61,6 +64,9 @@ func getTransport(conf *TransportConfig) *http.Transport {
proxyFunc = http.ProxyFromEnvironment
}
+ // This is the documented way to disable http2. However if a custom tls.Config or
+ // DialContext is used h2 will also be disabled. To enable h2 the transport must be
+ // explicitly configured, this can be done with the 'ForceAttemptHTTP2' below.
var nextProto map[string]func(authority string, c *tls.Conn) http.RoundTripper
if !conf.HTTP2 {
nextProto = make(map[string]func(authority string, c *tls.Conn) http.RoundTripper)
@@ -74,11 +80,9 @@ func getTransport(conf *TransportConfig) *http.Transport {
}
return conn, nil
},
- Dial: (&net.Dialer{
- KeepAlive: 60 * time.Second,
- }).Dial,
DisableCompression: true,
DisableKeepAlives: conf.DisableConnectionReuse,
+ ForceAttemptHTTP2: conf.HTTP2,
MaxConnsPerHost: conf.MaxConnections,
Proxy: proxyFunc,
ResponseHeaderTimeout: conf.TTFBTimeout,
