-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Minimal API with IFormFile throws when request body is missing and Content-Type header is missing or empty #53630
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
Comments
We should return 400 if the form isn't a valid content type rather than throwing (as part of the minimal API codegen). |
Just to make it clear, you mean 400, not 415? Because non-empty but invalid already returns 415. Should missing/empty be treated differently? |
Actually, now I'm wondering why this isn't working: aspnetcore/src/Http/Http.Extensions/src/RequestDelegateFactory.cs Lines 1487 to 1492 in de12f70
|
I don't think that's being used here, since it'd also accept
so I get 415, as expected. |
Update: the exception only happens if both of these are true:
I've updated the issue's title. The bug is in
|
Is there an existing issue for this?
Describe the bug
Having an endpoint with Minimal API and IFormFile:
Sending a request with incorrect Content-Type, ie:
will return 415 status, as expected. However, missing or empty (spaces) Content-Type, ie:
will throw InvalidOperationException and return 500. I am not 100% familiar with the code in this area (yet), but my understanding is that routing constraint won't exclude the endpoint for missing/empty Content-type, and then parameter binding will throw, while attempting to read HttpRequest.Form. The exception thrown is related to this issue: #49096
Tried changing the signature, with attribute and optional, same behaviour:
Expected Behavior
I expect that for endpoints with IFormFile (or its variations like IFormFileCollection) parameters, only valid Content-Type, ie.
Content-Type: multipart/form-data; ...
will be allowed, excluding missing or empty Content-Type headers. Only valid Content-Type would result in binding parameters from formSteps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.101
Anything else?
Checked this issue: #39430 but didn't find this explicitly.
I am happy to contribute, but first would need confirmation that this is indeed a bug and not a design decision I am unaware of 😃
The text was updated successfully, but these errors were encountered: