Skip to content

Pass in IFormFileCollection into minimal hosting delegate #35100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 9 additions & 4 deletions src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static partial class RequestDelegateFactory
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 FormFileExpr = Expression.Property(HttpContextExpr, nameof(HttpContext.Request.Form.Files));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't how we would do this. Reading the form body should be done asynchronously. We'd probably store state on the FactoryContext that describes this is a form body that needs files. Take a look at BindParameterFromBody and HandleRequestBodyAndCompileRequestDelegate

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 @@ -251,6 +252,10 @@ private static Expression CreateArgument(ParameterInfo parameter, FactoryContext
{
return RequestAbortedExpr;
}
else if (parameter.ParameterType == typeof(IFormFileCollection))
{
return FormFileExpr;
}
else if (parameter.ParameterType == typeof(string) || TryParseMethodCache.HasTryParseMethod(parameter))
{
// We're in the fallback case and we have a parameter and route parameter match so don't fallback
Expand Down Expand Up @@ -555,7 +560,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
Expression.IfThen(Expression.Equal(argument, Expression.Constant(null)),
Expression.Block(
Expression.Assign(WasParamCheckFailureExpr, Expression.Constant(true)),
Expression.Call(LogRequiredParameterNotProvidedMethod,
Expression.Call(LogRequiredParameterNotProvidedMethod,
HttpContextExpr, Expression.Constant(parameter.ParameterType.Name), Expression.Constant(parameter.Name))
)
)
Expand Down Expand Up @@ -652,7 +657,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
// if (tempSourceString == null)
// {
// wasParamCheckFailure = true;
// Log.RequiredParameterNotProvided(httpContext, "Int32", "param1");
// Log.RequiredParameterNotProvided(httpContext, "Int32", "param1");
// }
var checkRequiredParaseableParameterBlock = Expression.Block(
Expression.IfThen(TempSourceStringNullExpr,
Expand Down Expand Up @@ -685,7 +690,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
// if (tempSourceString == null) { ... } only produced when parameter is required
checkRequiredParaseableParameterBlock,
// if (tempSourceString != null) { ... }
ifNotNullTryParse)
ifNotNullTryParse)
: Expression.Block(
// tempSourceString = httpContext.RequestValue["id"];
Expression.Assign(TempSourceStringExpr, valueExpression),
Expand Down Expand Up @@ -740,7 +745,7 @@ private static Expression BindParameterFromBody(ParameterInfo parameter, bool al
Expression.Equal(argument, Expression.Constant(null)),
Expression.Block(
Expression.Assign(WasParamCheckFailureExpr, Expression.Constant(true)),
Expression.Call(LogRequiredParameterNotProvidedMethod,
Expression.Call(LogRequiredParameterNotProvidedMethod,
HttpContextExpr, Expression.Constant(parameter.ParameterType.Name), Expression.Constant(parameter.Name))
)
)
Expand Down