/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Transforms/ResponseTrailerValueTransform.cs
62 строки
2 KB
Miha Zupan
Make use of NonValidated headers (#1507)
11 янв 2022, 14:33
Не верифицирован
11 янв 2022, 14:33
e8c731e
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Threading.Tasks; using Microsoft.Extensions.Primitives; namespace Yarp.ReverseProxy.Transforms; /// <summary> /// Sets or appends simple response trailer values. /// </summary> public class ResponseTrailerValueTransform : ResponseTrailersTransform { public ResponseTrailerValueTransform(string headerName, string value, bool append, ResponseCondition condition) { if (string.IsNullOrEmpty(headerName)) { throw new ArgumentException($"'{nameof(headerName)}' cannot be null or empty.", nameof(headerName)); } HeaderName = headerName; Value = value ?? throw new ArgumentNullException(nameof(value)); Append = append; Condition = condition; } internal ResponseCondition Condition { get; } internal bool Append { get; } internal string HeaderName { get; } internal string Value { get; } // Assumes the response status code has been set on the HttpContext already. /// <inheritdoc/> public override ValueTask ApplyAsync(ResponseTrailersTransformContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (Condition == ResponseCondition.Always || Success(context) == (Condition == ResponseCondition.Success)) { if (Append) { var existingHeader = TakeHeader(context, HeaderName); var value = StringValues.Concat(existingHeader, Value); SetHeader(context, HeaderName, value); } else { SetHeader(context, HeaderName, Value); } } return default; } }