diff --git a/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs b/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs index 11eaa3bb8a31..c2fa07f21b7f 100644 --- a/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs +++ b/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs @@ -6,7 +6,6 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; -using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs; @@ -15,11 +14,11 @@ public class WebhookFiring : IRecurringBackgroundJob { private readonly ILogger _logger; private readonly IWebhookRequestService _webhookRequestService; - private readonly IJsonSerializer _jsonSerializer; private readonly IWebhookLogFactory _webhookLogFactory; private readonly IWebhookLogService _webhookLogService; private readonly IWebhookService _webHookService; private readonly ICoreScopeProvider _coreScopeProvider; + private readonly IHttpClientFactory _httpClientFactory; private WebhookSettings _webhookSettings; public TimeSpan Period => _webhookSettings.Period; @@ -32,20 +31,20 @@ public event EventHandler PeriodChanged { add { } remove { } } public WebhookFiring( ILogger logger, IWebhookRequestService webhookRequestService, - IJsonSerializer jsonSerializer, IWebhookLogFactory webhookLogFactory, IWebhookLogService webhookLogService, IWebhookService webHookService, IOptionsMonitor webhookSettings, - ICoreScopeProvider coreScopeProvider) + ICoreScopeProvider coreScopeProvider, + IHttpClientFactory httpClientFactory) { _logger = logger; _webhookRequestService = webhookRequestService; - _jsonSerializer = jsonSerializer; _webhookLogFactory = webhookLogFactory; _webhookLogService = webhookLogService; _webHookService = webHookService; _coreScopeProvider = coreScopeProvider; + _httpClientFactory = httpClientFactory; _webhookSettings = webhookSettings.CurrentValue; webhookSettings.OnChange(x => _webhookSettings = x); } @@ -90,10 +89,11 @@ await Task.WhenAll(requests.Select(request => private async Task SendRequestAsync(IWebhook webhook, string eventName, string? serializedObject, int retryCount, CancellationToken cancellationToken) { - using var httpClient = new HttpClient(); + using HttpClient httpClient = _httpClientFactory.CreateClient(); var stringContent = new StringContent(serializedObject ?? string.Empty, Encoding.UTF8, MediaTypeNames.Application.Json); stringContent.Headers.TryAddWithoutValidation("Umb-Webhook-Event", eventName); + stringContent.Headers.TryAddWithoutValidation("Umb-Webhook-RetryCount", retryCount.ToString()); foreach (KeyValuePair header in webhook.Headers) { @@ -107,7 +107,7 @@ await Task.WhenAll(requests.Select(request => } catch (Exception ex) { - _logger.LogError(ex, "Error while sending webhook request for webhook {WebhookKey}.", webhook); + _logger.LogError(ex, "Error while sending webhook request for webhook {WebhookKey}.", webhook.Key); } var webhookResponseModel = new WebhookResponseModel