dotnet/aspnetcore

`RouteHandlerBuilder.Accepts` does not return 415 response when the request has no `Content-Type`

Open

#45,264 建立於 2022年11月24日

在 GitHub 查看
 (7 留言) (0 反應) (0 負責人)C# (10,653 fork)batch import
Docsarea-minimalhelp wantednet8_docathon

倉庫指標

Star
 (37,933 star)
PR 合併指標
 (平均合併 16天 9小時) (30 天內合併 258 個 PR)

描述

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This is probably a duplicate of #43794 but I would like to get further information on this issue, namely:

  1. If empty string is not in the list of content types to accept, why should empty string not be handled as 415?
  2. Given the current behavior of Accepts, is an explicit check for the existence of the Content-Type header required?

Code:

app.MapPut("/file", Created (HttpRequest request) =>
{
	return TypedResults.Created("https://example.org");
})
.WithOpenApi()
.Accepts<byte[]>("application/zip")
.Produces(StatusCodes.Status415UnsupportedMediaType);

Expected Behavior

415 Unsupported Media Type is returned.

Actual Behavior

201 Created is returned.

Steps To Reproduce

After dotnet run, make a PUT request with no header

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

貢獻者指南