/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Transforms/HttpMethodTransformFactory.cs
50 строк
2 KB
Kahbazi
File Scoped Namespaces (#1352)
12 ноя 2021, 21:53
Не верифицирован
12 ноя 2021, 21:53
44f13d9
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using Yarp.ReverseProxy.Transforms.Builder; namespace Yarp.ReverseProxy.Transforms; internal sealed class HttpMethodTransformFactory : ITransformFactory { internal static readonly string HttpMethodChangeKey = "HttpMethodChange"; internal static readonly string SetKey = "Set"; public bool Validate(TransformRouteValidationContext context, IReadOnlyDictionary<string, string> transformValues) { if (transformValues.TryGetValue(HttpMethodChangeKey, out var _)) { TransformHelpers.CheckTooManyParameters(transformValues, expected: 2); if (!transformValues.TryGetValue(SetKey, out var _)) { context.Errors.Add(new ArgumentException($"Unexpected parameters for HttpMethod: {string.Join(';', transformValues.Keys)}. Expected 'Set'")); } } else { return false; } return true; } public bool Build(TransformBuilderContext context, IReadOnlyDictionary<string, string> transformValues) { if (transformValues.TryGetValue(HttpMethodChangeKey, out var fromHttpMethod)) { TransformHelpers.CheckTooManyParameters(transformValues, expected: 2); if (transformValues.TryGetValue(SetKey, out var toHttpMethod)) { context.AddHttpMethodChange(fromHttpMethod, toHttpMethod); } } else { return false; } return true; } }