Skip to content

Accepts Extension method for null Content-Type in Minimal API #43794

Closed
@rachna-lad

Description

@rachna-lad

Is there an existing issue for this?

  • I have searched the existing issues

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

  1. Use extension method Accepts which supports only specific Content-Type otherwise throw 415. Here i have taken application/json.
  2. Now make API request without request body(body is null) and Content-Type is also null
  3. Verify response

Exceptions (if any)

No response

.NET Version

6.0.101

Anything else?

No response

Metadata

Metadata

Assignees

Labels

✔️ Resolution: By DesignResolved because the behavior in this issue is the intended design.Status: ResolvedbugThis issue describes a behavior which is not expected - a bug.old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions