Skip to content

Commit 2f8a5b6

Browse files
authored
Don't execute handler after filter if StatusCode >= 400
1 parent be5a2ac commit 2f8a5b6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Http/Http.Abstractions/src/IRouteHandlerFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface IRouteHandlerFilter
1414
/// </summary>
1515
/// <param name="context">The <see cref="RouteHandlerFilterContext"/> associated with the current request/response.</param>
1616
/// <param name="next">The next filter in the pipeline.</param>
17-
/// <returns>The result of calling the current filter.</returns>
17+
/// <returns>An awaitable result of calling the handler and apply
18+
/// any modifications made by filters in the pipeline.</returns>
1819
ValueTask<object?> InvokeAsync(RouteHandlerFilterContext context, Func<RouteHandlerFilterContext, ValueTask<object?>> next);
1920
}

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ private static FactoryContext CreateFactoryContext(RequestDelegateFactoryOptions
225225
private static Func<RouteHandlerFilterContext, ValueTask<object?>> CreateFilterPipeline(MethodInfo methodInfo, Expression? target, FactoryContext factoryContext)
226226
{
227227
Debug.Assert(factoryContext.Filters is not null);
228-
// httpContext.Response.StatusCode == 400
228+
// httpContext.Response.StatusCode >= 400
229229
// ? Task.CompletedTask
230230
// : handler((string)context.Parameters[0], (int)context.Parameters[1])
231231
var filteredInvocation = Expression.Lambda<Func<RouteHandlerFilterContext, ValueTask<object?>>>(
232232
Expression.Condition(
233-
Expression.Equal(FilterContextHttpContextStatusCodeExpr, Expression.Constant(400)),
233+
Expression.GreaterThanOrEqual(FilterContextHttpContextStatusCodeExpr, Expression.Constant(400)),
234234
CompletedValueTaskExpr,
235235
Expression.Block(
236236
new[] { TargetExpr },

0 commit comments

Comments
 (0)