/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Transforms/ResponseHeaderRemoveTransform.cs
46 строк
1 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.Threading.Tasks; namespace Yarp.ReverseProxy.Transforms; /// <summary> /// Removes a response header. /// </summary> public class ResponseHeaderRemoveTransform : ResponseTransform { public ResponseHeaderRemoveTransform(string headerName, ResponseCondition condition) { if (string.IsNullOrEmpty(headerName)) { throw new ArgumentException($"'{nameof(headerName)}' cannot be null or empty.", nameof(headerName)); } HeaderName = headerName; Condition = condition; } internal string HeaderName { get; } internal ResponseCondition Condition { get; } // Assumes the response status code has been set on the HttpContext already. /// <inheritdoc/> public override ValueTask ApplyAsync(ResponseTransformContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (Condition == ResponseCondition.Always || Success(context) == (Condition == ResponseCondition.Success)) { context.HttpContext.Response.Headers.Remove(HeaderName); } return default; } }