-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix EmptyBodyBehavior with empty content-type #38092
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
Conversation
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.
Nice. I think there's a new feature we can use instead of checking for Content-Length
headers, we should consider updating the code to use that.
@@ -143,6 +143,11 @@ public async Task BindModelAsync(ModelBindingContext bindingContext) | |||
|
|||
if (formatter == null) | |||
{ | |||
if (AllowEmptyBody && httpContext.Request.ContentLength == 0) |
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.
@Tratcher isn't there a better way to check for empty bodies?
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.
bool CanHaveBody { get; } |
@@ -143,6 +143,11 @@ public async Task BindModelAsync(ModelBindingContext bindingContext) | |||
|
|||
if (formatter == null) | |||
{ | |||
if (AllowEmptyBody && httpContext.Request.ContentLength == 0) | |||
{ | |||
return; |
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 think you might need to do bindingContext.Result = ModelBindingResult.Success(model: null);
. See the comment on Line 178.
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.
Is there a test I should write for this? I'm not sure how this is visible
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.
Hmm, I think an actual case where problematic behavior might be observable if if you have a [FromBody]
property. But maybe we could just write a unit test that verify IsModelSet == true
?
0fd9346
to
ff7b27a
Compare
Fixes #36466