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 |
|
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.
nit:
| if (hasBody == false) | |
| if (!hasBody) |
There was a problem hiding this comment.
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.
pranavkm
left a comment
There was a problem hiding this comment.
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!
| public async Task FromBodyWithEmptyBody_AddsModelErrorWhenExpected( | ||
| Type modelType, | ||
| bool allowEmptyInputInBodyModelBindingSetting, | ||
| bool expectedModelStateIsValid) |
There was a problem hiding this comment.
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.
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 == nullwill now be detected as Empty Body.aspnetcore/src/Http/Http.Features/src/IHttpRequestBodyDetectionFeature.cs
Line 11 in 15fa3ad
Before:
csharp request.ContentLength == 0After:
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