fix(common.http): Keep timeout after creating oauth client (#15900)

This commit is contained in:
lestrozi 2024-09-19 10:32:19 +01:00 committed by GitHub
parent 253a114622
commit d77cf92d6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 6 deletions

View File

@ -54,16 +54,12 @@ func (h *HTTPClientConfig) CreateClient(ctx context.Context, log telegraf.Logger
// Register "http+unix" and "https+unix" protocol handler.
unixtransport.Register(transport)
timeout := h.Timeout
if timeout == 0 {
timeout = config.Duration(time.Second * 5)
}
client := &http.Client{
Transport: transport,
Timeout: time.Duration(timeout),
}
// While CreateOauth2Client returns a http.Client keeping the Transport configuration,
// it does not keep other http.Client parameters (e.g. Timeout).
client = h.OAuth2Config.CreateOauth2Client(ctx, client)
if h.CookieAuthConfig.URL != "" {
@ -72,5 +68,11 @@ func (h *HTTPClientConfig) CreateClient(ctx context.Context, log telegraf.Logger
}
}
timeout := h.Timeout
if timeout == 0 {
timeout = config.Duration(time.Second * 5)
}
client.Timeout = time.Duration(timeout)
return client, nil
}