/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/ReverseProxy.Transforms.Sample/MyTransformFactory.cs
49 строк
2 KB
Miha Zupan
Drop 3.1 and 5.0 TFMs (#1728)
23 май 2022, 20:08
Не верифицирован
23 май 2022, 20:08
94bd127
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.Net.Http; using Yarp.ReverseProxy.Transforms; using Yarp.ReverseProxy.Transforms.Builder; namespace Yarp.Sample { internal class MyTransformFactory : ITransformFactory { public bool Validate(TransformRouteValidationContext context, IReadOnlyDictionary<string, string> transformValues) { if (transformValues.TryGetValue("CustomTransform", out var value)) { if (string.IsNullOrEmpty(value)) { context.Errors.Add(new ArgumentException("A non-empty CustomTransform value is required")); } return true; // Matched } return false; } public bool Build(TransformBuilderContext context, IReadOnlyDictionary<string, string> transformValues) { if (transformValues.TryGetValue("CustomTransform", out var value)) { if (string.IsNullOrEmpty(value)) { throw new ArgumentException("A non-empty CustomTransform value is required"); } context.AddRequestTransform(transformContext => { transformContext.ProxyRequest.Options.Set(new HttpRequestOptionsKey<string>("CustomTransform"), value); return default; }); return true; } return false; } } }