/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Health/DefaultProbingRequestFactory.cs
42 строки
2 KB
robbieknuth
Allow for using query strings in DefaultProbingRequestFactory. (#2421)
12 мар 2024, 13:50
Не верифицирован
12 мар 2024, 13:50
3c6ff2c
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Net; using System.Net.Http; using System.Reflection; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.Net.Http.Headers; using Yarp.ReverseProxy.Model; namespace Yarp.ReverseProxy.Health; internal sealed class DefaultProbingRequestFactory : IProbingRequestFactory { private static readonly string? _version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; private static readonly string _defaultUserAgent = $"YARP{(string.IsNullOrEmpty(_version) ? "" : $"/{_version.Split('+')[0]}")} (Active Health Check Monitor)"; public HttpRequestMessage CreateRequest(ClusterModel cluster, DestinationModel destination) { var probeAddress = !string.IsNullOrEmpty(destination.Config.Health) ? destination.Config.Health : destination.Config.Address; var probePath = cluster.Config.HealthCheck?.Active?.Path; UriHelper.FromAbsolute(probeAddress, out var destinationScheme, out var destinationHost, out var destinationPathBase, out _, out _); var query = QueryString.FromUriComponent(cluster.Config.HealthCheck?.Active?.Query ?? ""); var probeUri = UriHelper.BuildAbsolute(destinationScheme, destinationHost, destinationPathBase, probePath, query); var request = new HttpRequestMessage(HttpMethod.Get, probeUri) { Version = cluster.Config.HttpRequest?.Version ?? HttpVersion.Version20, VersionPolicy = cluster.Config.HttpRequest?.VersionPolicy ?? HttpVersionPolicy.RequestVersionOrLower, }; if (!string.IsNullOrEmpty(destination.Config.Host)) { request.Headers.Add(HeaderNames.Host, destination.Config.Host); } request.Headers.Add(HeaderNames.UserAgent, _defaultUserAgent); return request; } }