From ec4aa606e213639d68339d34d43b826846c594df Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 17 Oct 2023 19:50:45 +0200 Subject: [PATCH] chore(webhooks): reuse webhook client --- pkg/models/webhooks.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/models/webhooks.go b/pkg/models/webhooks.go index 36debf4b3ac..39dc5c575d8 100644 --- a/pkg/models/webhooks.go +++ b/pkg/models/webhooks.go @@ -37,6 +37,8 @@ import ( "xorm.io/xorm" ) +var webhookClient *http.Client + type Webhook struct { ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"webhook"` TargetURL string `xorm:"not null" valid:"minstringlength(1)" minLength:"1" json:"target_url"` @@ -142,10 +144,16 @@ func (w *Webhook) Delete(s *xorm.Session, a web.Auth) (err error) { } func getWebhookHTTPClient() (client *http.Client) { + + if webhookClient != nil { + return webhookClient + } + client = http.DefaultClient client.Timeout = time.Duration(config.WebhooksTimeoutSeconds.GetInt()) * time.Second if config.WebhooksProxyURL.GetString() == "" || config.WebhooksProxyPassword.GetString() == "" { + webhookClient = client return } @@ -159,6 +167,8 @@ func getWebhookHTTPClient() (client *http.Client) { }, } + webhookClient = client + return }