dotnet / dotnet/aspnetcore

[Consumes] attribute does not accept wildcard media types

Open
#63,901 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

`ConsumesAttribute` constructors use `GetContentTypes()` to populate the `ContentTypes` property and to ensure that no wildcard media types are used:

https://github.com/dotnet/aspnetcore/blob/4f8086c41755f61ce2c5988f2f6ee0d305dbd0b8/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs#L236C1-L256C6

This effectively forbids declarations like:

```c#
[Consumes("text/*")]
public IActionResult SomeAction() { ... }
```

However, the `Accept()` method uses `IsSubsetOfAnyContentType()` to check if a request's content type is a subtype of a media type in `ContentTypes`:

https://github.com/dotnet/aspnetcore/blob/4f8086c41755f61ce2c5988f2f6ee0d305dbd0b8/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs#L128C1-L141C1

### Expected Behavior

I believe that `[Consumes]` should allow wildcard media types, unless there's some side effect that I cannot see. Regardless of wheter `[FromBody]` is used or not, just the ability to filter on media subtypes is really useful.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

9.0.305

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.