Increase default timeout for SaneHttpClient, but fail early. (#587)

* Increase default timeout for SaneHttpClient, but fail early.

* Don't change default for client with timeout
This commit is contained in:
Dustin Decker 2022-05-26 11:08:38 -07:00 committed by GitHub
parent 143fa333f3
commit c52545a0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -121,10 +121,24 @@ func RetryableHttpClient() *http.Client {
return httpClient.StandardClient()
}
const DefaultResponseTimeout = 5 * time.Second
var saneTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 2 * time.Second,
KeepAlive: 5 * time.Second,
}).DialContext,
MaxIdleConns: 5,
IdleConnTimeout: 5 * time.Second,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
func SaneHttpClient() *http.Client {
httpClient := &http.Client{}
httpClient.Timeout = time.Second * 2
httpClient.Transport = NewCustomTransport(nil)
httpClient.Timeout = DefaultResponseTimeout
httpClient.Transport = NewCustomTransport(saneTransport)
return httpClient
}