/
aprogrammer
/
reverse-proxy-ms-yarp
Обзор
Документация
Войти
/
aprogrammer
/
reverse-proxy-ms-yarp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ReverseProxy/Transforms/ResponseTrailerRemoveTransform.cs
56 строк
2 KB
Kahbazi
Use is null instead of == null (#1565)
29 мар 2022, 02:51
Не верифицирован
29 мар 2022, 02:51
9bbdf5e
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; namespace Yarp.ReverseProxy.Transforms; /// <summary> /// Removes a response trailer. /// </summary> public class ResponseTrailerRemoveTransform : ResponseTrailersTransform { public ResponseTrailerRemoveTransform(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(ResponseTrailersTransformContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } Debug.Assert(context.ProxyResponse is not null); if (Condition == ResponseCondition.Always || Success(context) == (Condition == ResponseCondition.Success)) { var responseTrailersFeature = context.HttpContext.Features.Get<IHttpResponseTrailersFeature>(); var responseTrailers = responseTrailersFeature?.Trailers; // Support should have already been checked by the caller. Debug.Assert(responseTrailers is not null); Debug.Assert(!responseTrailers.IsReadOnly); responseTrailers.Remove(HeaderName); } return default; } }