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
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 4 additions and 4 deletions

View file

@ -239,7 +239,7 @@ The configuration file contains the following sections:
- `certificate_key_file`, string. Private key matching the above certificate. This can be an absolute path or a path relative to the config dir. If both the certificate and the private key are provided, the server will expect HTTPS connections. Certificate and key files can be reloaded on demand sending a `SIGHUP` signal on Unix based systems and a `paramchange` request to the running service on Windows.
- `tls_cipher_suites`, list of strings. List of supported cipher suites for TLS version 1.2. If empty, a default list of secure cipher suites is used, with a preference order based on hardware performance. Note that TLS 1.3 ciphersuites are not configurable. The supported ciphersuites names are defined [here](https://github.com/golang/go/blob/master/src/crypto/tls/cipher_suites.go#L52). Any invalid name will be silently ignored. The order matters, the ciphers listed first will be the preferred ones. Default: empty.
- **"http"**, the configuration for HTTP clients. HTTP clients are used for executing hooks. Some hooks use a retryable HTTP client, for these hooks you can configure the time between retries and the number of retries. Please check the hook specific documentation to understand which hooks use a retryable HTTP client.
- `timeout`, integer. Timeout specifies a time limit, in seconds, for requests. For requests with retries this is the timeout for a single request
- `timeout`, float. Timeout specifies a time limit, in seconds, for requests. For requests with retries this is the timeout for a single request
- `retry_wait_min`, integer. Defines the minimum waiting time between attempts in seconds.
- `retry_wait_max`, integer. Defines the maximum waiting time between attempts in seconds. The backoff algorithm will perform exponential backoff based on the attempt number and limited by the provided minimum and maximum durations.
- `retry_max`, integer. Defines the maximum number of retries if the first request fails.

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