Equip default transport with reduced connect timeout

This commit is contained in:
andig 2022-03-15 19:25:38 +00:00
parent 3537f2de50
commit 6972bc6c36
2 changed files with 16 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import (
"time"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/transport"
)
// Timeout is the default request timeout used by the Helper
@ -21,7 +22,7 @@ func NewHelper(log *util.Logger) *Helper {
r := &Helper{
Client: &http.Client{
Timeout: Timeout,
Transport: NewTripper(log, http.DefaultTransport),
Transport: NewTripper(log, transport.Default()),
},
}

View file

@ -2,16 +2,25 @@ package transport
import (
"crypto/tls"
"net"
"net/http"
"time"
)
// Default returns http.DefaultTransport as http.Transport instead of http.RoundTripper
// Default returns an http.DefaultTransport as http.Transport with reduced dial timeout
func Default() *http.Transport {
t, ok := http.DefaultTransport.(*http.Transport)
if !ok {
panic("http.DefaultTransport is not an http.Transport")
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 5 * time.Second, // reduced from 30s
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return t
}
// InsecureTransport is an http.Transport with TLSClientConfig.InsecureSkipVerify enabled