-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Allowing empty FromBody parameters input based on nullability #39917
Allowing empty FromBody parameters input based on nullability #39917
Conversation
/benchmark |
That's not worked yet Edit: Nvm? |
Crank - Pull Request Bot
Benchmarks:
Profiles:
Components:
|
/benchmark plaintext aspnet-perf-win,aspnet-perf-lin mvc |
src/Mvc/Mvc.Core/src/ApplicationModels/InferParameterBindingInfoConvention.cs
Outdated
Show resolved
Hide resolved
Benchmark started for plaintext on aspnet-perf-win, aspnet-perf-lin with mvc |
Failed to benchmark PR #39917. Skipping... Details:
|
The AFAICT, the only per-request change is the change to |
/benchmark mvcjsoninput2k aspnet-perf-lin mvc |
Benchmark started for mvcjsoninput2k on aspnet-perf-lin with mvc |
mvcjsoninput2k - aspnet-perf-lin
|
// In case the feature is not registered | ||
hasBody ??= context.HttpContext.Request.ContentLength != 0; | ||
|
||
if (hasBody == false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
if (hasBody == false) | |
if (!hasBody) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a Nullable<bool>
. This is basically a saying "if we know for sure this request cannot have a body ..." Probably worth a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd look at using ParameterDefaultValue
- it might be that the bugs it was trying to workaround have since been resolved, but everything else looks great. Thanks for driving this!
src/Mvc/Mvc.Core/src/ApplicationModels/InferParameterBindingInfoConvention.cs
Show resolved
Hide resolved
[InlineData(typeof(Person5WithNullableContext), true, false)] | ||
[InlineData(typeof(Person5WithNullableContext), false, false)] | ||
public async Task FromBodyWithEmptyBody_AddsModelErrorWhenExpected( | ||
Type modelType, | ||
bool allowEmptyInputInBodyModelBindingSetting, | ||
bool expectedModelStateIsValid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bad test because it's representing test branches as data. I realize you didn't write it, but could we split this in to two tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have split the test into FromBodyWithEmptyBody_ModelStateIsInvalid_HasModelErrors
and FromBodyWithEmptyBody_ModelStateIsValid_WhenAllowEmptyInput
, is that good?
Co-authored-by: Pranav K <prkrishn@hotmail.com>
…ns16/aspnetcore into brunolins16/issues/39754
Description
This PR introduces two breaking changes:
Empty Input body calculation (a5a47b0)
The biggest change is, in most cases, the
Content-Length == null
will now be detected as Empty Body.aspnetcore/src/Http/Http.Features/src/IHttpRequestBodyDetectionFeature.cs
Line 11 in 15fa3ad
Before:
csharp request.ContentLength == 0
After:
Allowing empty FromBody parameters input based on nullability
As described in the #39754 some parameters will now be allowed as empty input parameter.
Fixes #39754 #29570