Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support Request, Response and User for minimal actions
Adds support to minimal actions for parameters of type HttpRequest,
HttpResponse, and ClaimsPrincipal to be bound to the values of the
Request, Response and User properties of the HttpContext respectively.

Also cleans up some typos in the RequestDelegateFactory tests.

Addresses #33870.
  • Loading branch information
martincostello committed Jun 27, 2021
commit fe899627fc8a462c49ebf762d40efe9bab4205bd
14 changes: 14 additions & 0 deletions src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Metadata;
Expand Down Expand Up @@ -45,6 +46,7 @@ public static class RequestDelegateFactory
private static readonly MemberExpression HttpRequestExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.Request));
private static readonly MemberExpression HttpResponseExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.Response));
private static readonly MemberExpression RequestAbortedExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.RequestAborted));
private static readonly MemberExpression UserExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.User));
private static readonly MemberExpression RouteValuesExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.RouteValues));
private static readonly MemberExpression QueryExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.Query));
private static readonly MemberExpression HeadersExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.Headers));
Expand Down Expand Up @@ -221,6 +223,18 @@ private static Expression CreateArgument(ParameterInfo parameter, FactoryContext
{
return HttpContextExpr;
}
else if (parameter.ParameterType == typeof(HttpRequest))
{
return HttpRequestExpr;
}
else if (parameter.ParameterType == typeof(HttpResponse))
{
return HttpResponseExpr;
}
else if (parameter.ParameterType == typeof(ClaimsPrincipal))
{
return UserExpr;
}
Comment thread
martincostello marked this conversation as resolved.
else if (parameter.ParameterType == typeof(CancellationToken))
{
return RequestAbortedExpr;
Expand Down
Loading