httpclient: accepts timeouts as float

Fixes #428
This commit is contained in:
Nicola Murino
2021-05-16 12:50:06 +02:00
parent 019b0f2fd5
commit 8ecf64f481
2 changed files with 4 additions and 4 deletions

View File

@@ -26,7 +26,7 @@ type TLSKeyPair struct {
// custom actions, external authentication and pre-login user modifications
type Config struct {
// Timeout specifies a time limit, in seconds, for a request
Timeout int64 `json:"timeout" mapstructure:"timeout"`
Timeout float64 `json:"timeout" mapstructure:"timeout"`
// RetryWaitMin defines the minimum waiting time between attempts in seconds
RetryWaitMin int `json:"retry_wait_min" mapstructure:"retry_wait_min"`
// RetryWaitMax defines the minimum waiting time between attempts in seconds
@@ -144,7 +144,7 @@ func (c *Config) loadCertificates(configDir string) error {
// GetHTTPClient returns an HTTP client with the configured parameters
func GetHTTPClient() *http.Client {
return &http.Client{
Timeout: time.Duration(httpConfig.Timeout) * time.Second,
Timeout: time.Duration(httpConfig.Timeout * float64(time.Second)),
Transport: httpConfig.customTransport,
}
}
@@ -153,7 +153,7 @@ func GetHTTPClient() *http.Client {
// It uses the configured retry parameters
func GetRetraybleHTTPClient() *retryablehttp.Client {
client := retryablehttp.NewClient()
client.HTTPClient.Timeout = time.Duration(httpConfig.Timeout) * time.Second
client.HTTPClient.Timeout = time.Duration(httpConfig.Timeout * float64(time.Second))
client.HTTPClient.Transport.(*http.Transport).TLSClientConfig = httpConfig.tlsConfig
client.Logger = &logger.LeveledLogger{Sender: "RetryableHTTPClient"}
client.RetryWaitMin = time.Duration(httpConfig.RetryWaitMin) * time.Second