Files
jinko.yikatong/Src/Dlhis.Middle/Apis/Handlers/HealthzClientHandler.cs
2024-12-13 16:32:27 +08:00

34 lines
1.2 KiB
C#

using System.Net;
using Kurisu.RemoteCall.Abstractions;
using Polly;
using Polly.Extensions.Http;
namespace Dlhis.Middle.Apis.Handlers;
public class HealthzClientHandler : IHttpRemoteCallPolicyHandler
{
/// <inheritdoc />
public IHttpClientBuilder ConfigureHttpClient(IHttpClientBuilder builder)
{
builder.ConfigureHttpClient(client => { client.Timeout = TimeSpan.FromSeconds(10); }).ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
};
return handler;
})
//.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddPolicyHandler(
HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(x => x.StatusCode != HttpStatusCode.OK)
//.OrResult(msg => msg.StatusCode != HttpStatusCode.OK)
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
);
return builder;
}
}