/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Routing/QueryParameterMatcher.cs
63 строки
2 KB
Miha Zupan
Add support for multi-value header routing (#1639)
20 апр 2022, 18:36
Не верифицирован
20 апр 2022, 18:36
b24e71c
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.Linq; using Yarp.ReverseProxy.Configuration; namespace Yarp.ReverseProxy.Routing; /// <summary> /// A request query parameter matcher used during routing. /// </summary> internal sealed class QueryParameterMatcher { /// <summary> /// Creates a new instance. /// </summary> public QueryParameterMatcher(string name, IReadOnlyList<string>? values, QueryParameterMatchMode mode, bool isCaseSensitive) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("A query parameter name is required.", nameof(name)); } if (mode != QueryParameterMatchMode.Exists && (values is null || values.Count == 0)) { throw new ArgumentException("Query parameter values must have at least one value.", nameof(values)); } if (mode == QueryParameterMatchMode.Exists && values?.Count > 0) { throw new ArgumentException($"Query parameter values must not be specified when using '{nameof(QueryParameterMatchMode.Exists)}'.", nameof(values)); } if (values is not null && values.Any(string.IsNullOrEmpty)) { throw new ArgumentNullException(nameof(values), "Query parameter values must not be empty."); } Name = name; Values = values?.ToArray() ?? Array.Empty<string>(); Mode = mode; Comparison = isCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; } /// <summary> /// Name of the query parameter to look for. /// </summary> public string Name { get; } /// <summary> /// Returns a read-only collection of acceptable query parameter values used during routing. /// At least one value is required unless <see cref="Mode"/> is set to <see cref="QueryParameterMatchMode.Exists"/>. /// </summary> public string[] Values { get; } /// <summary> /// Specifies how query parameter values should be compared (e.g. exact matches Vs. contains). /// Defaults to <see cref="QueryParameterMatchMode.Exact"/>. /// </summary> public QueryParameterMatchMode Mode { get; } public StringComparison Comparison { get; } }