diff --git a/src/Umbraco.Core/HealthChecks/Checks/Security/HttpsCheck.cs b/src/Umbraco.Core/HealthChecks/Checks/Security/HttpsCheck.cs index dbff50c480..888b136360 100644 --- a/src/Umbraco.Core/HealthChecks/Checks/Security/HttpsCheck.cs +++ b/src/Umbraco.Core/HealthChecks/Checks/Security/HttpsCheck.cs @@ -25,7 +25,6 @@ public class HttpsCheck : HealthCheck private const int NumberOfDaysForExpiryWarning = 14; private const string HttpPropertyKeyCertificateDaysToExpiry = "CertificateDaysToExpiry"; - private static HttpClient? _httpClient; private readonly IOptionsMonitor _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; @@ -46,12 +45,6 @@ public class HttpsCheck : HealthCheck _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; } - - private static HttpClient _httpClientEnsureInitialized => _httpClient ??= new HttpClient(new HttpClientHandler - { - ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation, - }); - /// public override async Task> GetStatus() => await Task.WhenAll( @@ -72,8 +65,7 @@ public class HttpsCheck : HealthCheck { if (certificate is not null) { - requestMessage.Properties[HttpPropertyKeyCertificateDaysToExpiry] = - (int)Math.Floor((certificate.NotAfter - DateTime.Now).TotalDays); + requestMessage.Options.Set(new HttpRequestOptionsKey(HttpPropertyKeyCertificateDaysToExpiry), (int?)Math.Floor((certificate.NotAfter - DateTime.Now).TotalDays)); } return sslErrors == SslPolicyErrors.None; @@ -92,17 +84,22 @@ public class HttpsCheck : HealthCheck try { - using HttpResponseMessage response = await _httpClientEnsureInitialized.SendAsync(request); + using var httpClient = new HttpClient(new HttpClientHandler + { + ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation, + }); + + using HttpResponseMessage response = await httpClient.SendAsync(request); if (response.StatusCode == HttpStatusCode.OK) { // Got a valid response, check now if the certificate is expiring within the specified amount of days int? daysToExpiry = 0; - if (request.Properties.TryGetValue( - HttpPropertyKeyCertificateDaysToExpiry, - out var certificateDaysToExpiry)) + if (response.RequestMessage != null && response.RequestMessage.Options.TryGetValue( + new HttpRequestOptionsKey(HttpPropertyKeyCertificateDaysToExpiry), + out var certificateDaysToExpiry)) { - daysToExpiry = (int?)certificateDaysToExpiry; + daysToExpiry = certificateDaysToExpiry; } if (daysToExpiry <= 0)