dotnet / dotnet/aspnetcore

Allow content type header in response to contain chartset=utf-8 encoding

Open
#56,299 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

### Is your feature request related to a problem? Please describe the problem.

I am using a aspnetcore project for my server, and for calls in which the controller raises an exception and for successful ones we're able to return the content type header with `application/json; charset=utf-8`. However, for errors in which the controller does not raise an exception such as 400/Bad Request, I can't seem to be able to configure this because the response message starts to be written somewhere in the asp net core middlewares we are using (I believe in our case it's during the Authorization middleware but I couldn't find the exact point with the Debugger alone).

Looking at the code, it looks like content-type header for bad requests is hardcoded as `application/json` according to this part of the code: https://github.com/dotnet/aspnetcore/blob/42925a4cebf501fd00aae1a1e899a969b4a2bd9a/src/Http/Http.Results/src/BadRequestOfT.cs#L63-L68

### Describe the solution you'd like

I'd like to know if there's a way where we can override the asp net core middlewares on our side to set the response's content-type to `application/json; charset=utf-8`. If not, I'm happy to send a PR to change line 68 of the piece of code above.

### Additional context

I believe the descriptions are already good enough but I'm happy to provide more information if required.

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.