/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Health/PassiveHealthCheckMiddleware.cs
41 строка
1 KB
Miha Zupan
Use frozen collections (#2272)
03 окт 2023, 23:35
Не верифицирован
03 окт 2023, 23:35
0229054
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Frozen; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Yarp.ReverseProxy.Utilities; namespace Yarp.ReverseProxy.Health; public class PassiveHealthCheckMiddleware { private readonly RequestDelegate _next; private readonly FrozenDictionary<string, IPassiveHealthCheckPolicy> _policies; public PassiveHealthCheckMiddleware(RequestDelegate next, IEnumerable<IPassiveHealthCheckPolicy> policies) { _next = next ?? throw new ArgumentNullException(nameof(next)); _policies = policies?.ToDictionaryByUniqueId(p => p.Name) ?? throw new ArgumentNullException(nameof(policies)); } public async Task Invoke(HttpContext context) { await _next(context); var proxyFeature = context.GetReverseProxyFeature(); var options = proxyFeature.Cluster.Config.HealthCheck?.Passive; // Do nothing if no target destination has been chosen for the request. if (options is null || !options.Enabled.GetValueOrDefault() || proxyFeature.ProxiedDestination is null) { return; } var policy = _policies.GetRequiredServiceById(options.Policy, HealthCheckConstants.PassivePolicy.TransportFailureRate); var cluster = context.GetRouteModel().Cluster!; policy.RequestProxied(context, cluster, proxyFeature.ProxiedDestination); } }