Reconfigure timeouts

This commit is contained in:
Ben Sarmiento
2024-01-26 13:51:48 +01:00
parent b72514c25e
commit 9e03cf6510
3 changed files with 10 additions and 9 deletions

View File

@@ -52,10 +52,8 @@ func (e *ApiErrorResponse) Error() string {
func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host bool, cfg config.ConfigInterface, log *logutil.Logger) *HTTPClient {
client := HTTPClient{
bearerToken: token,
client: &http.Client{
Timeout: time.Duration(timeoutSecs) * time.Second,
},
maxRetries: maxRetries,
client: &http.Client{},
maxRetries: maxRetries,
backoff: func(attempt int) time.Duration {
maxDuration := 60
backoff := int(math.Pow(2, float64(attempt)))
@@ -110,7 +108,9 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host
log: log,
}
var dialer proxy.Dialer = &net.Dialer{}
var dialer proxy.Dialer = &net.Dialer{
Timeout: time.Duration(timeoutSecs) * time.Second,
}
if proxyURLString := cfg.GetProxy(); proxyURLString != "" {
proxyURL, err := url.Parse(proxyURLString)
if err != nil {
@@ -140,8 +140,9 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host
}
client.client.Transport = &http.Transport{
MaxIdleConns: maxConnections,
MaxConnsPerHost: maxConnections,
ResponseHeaderTimeout: time.Duration(timeoutSecs) * time.Second,
MaxIdleConns: 0,
MaxConnsPerHost: maxConnections,
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
if ipv6Address, ok := client.ipv6.Get(address); ok {
return dialer.Dial(network, ipv6Address)