Skip to content

Commit 1b819d0

Browse files
Support Request, Response and User for minimal actions (dotnet#33883)
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 dotnet#33870.
1 parent 000a803 commit 1b819d0

File tree

2 files changed

+118
-43
lines changed

2 files changed

+118
-43
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Linq.Expressions;
99
using System.Reflection;
10+
using System.Security.Claims;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using Microsoft.AspNetCore.Http.Metadata;
@@ -45,6 +46,7 @@ public static class RequestDelegateFactory
4546
private static readonly MemberExpression HttpRequestExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.Request));
4647
private static readonly MemberExpression HttpResponseExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.Response));
4748
private static readonly MemberExpression RequestAbortedExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.RequestAborted));
49+
private static readonly MemberExpression UserExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.User));
4850
private static readonly MemberExpression RouteValuesExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.RouteValues));
4951
private static readonly MemberExpression QueryExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.Query));
5052
private static readonly MemberExpression HeadersExpr = Expression.Property(HttpRequestExpr, nameof(HttpRequest.Headers));
@@ -221,6 +223,18 @@ private static Expression CreateArgument(ParameterInfo parameter, FactoryContext
221223
{
222224
return HttpContextExpr;
223225
}
226+
else if (parameter.ParameterType == typeof(HttpRequest))
227+
{
228+
return HttpRequestExpr;
229+
}
230+
else if (parameter.ParameterType == typeof(HttpResponse))
231+
{
232+
return HttpResponseExpr;
233+
}
234+
else if (parameter.ParameterType == typeof(ClaimsPrincipal))
235+
{
236+
return UserExpr;
237+
}
224238
else if (parameter.ParameterType == typeof(CancellationToken))
225239
{
226240
return RequestAbortedExpr;

0 commit comments

Comments
 (0)