chore(webhooks): reuse webhook client

This commit is contained in:
kolaente 2023-10-17 19:50:45 +02:00
parent c3947e1016
commit ec4aa606e2
Signed by: konrad
GPG Key ID: F40E70337AB24C9B

View File

@ -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
}