Skip to content

Conversation

@BrennanConroy
Copy link
Member

Fixes #36466

@BrennanConroy BrennanConroy added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-model-binding labels Nov 4, 2021
Copy link
Contributor

@pranavkm pranavkm left a 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.


if (formatter == null)
{
if (AllowEmptyBody && httpContext.Request.ContentLength == 0)
Copy link
Contributor

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?

Copy link
Member

Choose a reason for hiding this comment

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

{
if (AllowEmptyBody && httpContext.Request.ContentLength == 0)
{
return;
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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?

@BrennanConroy BrennanConroy merged commit 783adbf into main Nov 12, 2021
@BrennanConroy BrennanConroy deleted the brecon/emptyBody branch November 12, 2021 21:23
@ghost ghost added this to the 7.0-preview1 milestone Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-model-binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EmptyBodyBehavior.Allow should allow a missing Content-Type

4 participants