-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Accepts Extension method for null Content-Type in Minimal API #43794
Comments
This appears to be a bug in the way the aspnetcore/src/Http/Routing/src/Matching/AcceptsMatcherPolicy.cs Lines 37 to 46 in 2c55745
To validate this assumption, I updated the implementation of bool IEndpointSelectorPolicy.AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints)
{
if (endpoints == null)
{
throw new ArgumentNullException(nameof(endpoints));
}
// When the node contains dynamic endpoints we can't make any assumptions.
if (ContainsDynamicEndpoints(endpoints))
{
return false;
}
return AppliesToEndpointsCore(endpoints);
} This seems to populate some nodes in the matcher with the correct policies, however the matcher doesn't pick up those candidate nodes during routing here.
A sidenote to all this analysis is that we do have content-type checks for minimal APIs generated in the RequestDelegateFactory. However, the rules are not nearly as robust as what you would get in the More notes incoming... |
OK, we spent some time discussing this in the team chat and @brunolins16 was able to provide some illuminating insights in this regard. TL;DR: this is expected behavior given the way the Request content types in minimal API applications are validated at two layers:
What logic comes into play depends on some rules that are enforced in the
#1 and #3 will evaluate to the underlying endpoint. The |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
I have used Accepts extension method to allow only specific Content-Type. Refer below code snippet for reference.
webApplication.MapPost("v1/todo", async (long id, [FromBody] TODO request) => { // Perform operation }) .Accepts<TODO>("application/json") .Produces(StatusCodes.Status415UnsupportedMediaType);
But this Accepts doesn't handle null Content-Type in header.
Expected Behavior
Should throw 415 if define Content-type is not passed in header.
Steps To Reproduce
Accepts
which supports only specific Content-Type otherwise throw 415. Here i have takenapplication/json
.Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
No response
The text was updated successfully, but these errors were encountered: