Skip to content

Remove default charset from 'application/json' Content-Type header #2567

@doortts

Description

@doortts

Issue Description

Using application/json; charset=UTF-8 in response header is a common misuse. I think it is better to remove ; charset=UTF-8 from default json response Content-Type header to prevent the misconception.

According to the documentation at rfc8259: JSON spec, JSON has only one encoding type, 'UTF-8'. JSON must be encoded by UTF-8, and there is no "charset" parameter.

The media type for JSON text is application/json.
...
Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.

Related RFC note link

8.1. Character Encoding

JSON text exchanged between systems that are not part of a closed
ecosystem MUST be encoded using UTF-8 [RFC3629].

Related RFC 8.1 Chapter Link

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

In response header:

Content-Type: application/json

Actual behaviour

Content-Type: application/json; charset=UTF-8

Steps to reproduce

any response when to response with JSON(code int, i interface{}),
default response Content-Type header contains ; charset=UTF-8.

Version/commit

v4.11.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions