Produces attribute does not honor Accept header.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Describe the bug
The ConsumesAttribute appears to honor the content-type header returning a 415 if there is a mismatch here. I was wondering why there is not similar behavior on the ProducesAttribute to honor the accept header.
### To Reproduce
1. Create a new WebApi project in .Net Core 3.1
2. Add the [Produces("application/vnd.api+json")] attribute to the Get method in the controller.
3. In startup.cs add the following
```
services.AddControllers(config =>
{
config.RespectBrowserAcceptHeader = true;
config.ReturnHttpNotAcceptable = true;
});
```
Attempt to hit the API using your tool of choice.
Set the accept header in the request to "application/json"
You will get a successful result with a content-type of application/vnd.api+json.
I get that the "Produces" attribute will always force the result of an API to before formatted as the type listed in the attribute, but if the accept header provided doesn't match the expected output type of an API does that not warrant a 406, especially in the case where RespectBrowserAcceptHeader is enabled?
### Exceptions (if any)
### Further technical details
- ASP.NET Core version 3.1.200
- Include the output of `dotnet --info`
- The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version VS 2019 Enterprise 16.8.2
Contributor guide
Assessment
This issue has not been assessed yet.