Content-type header for application/json should not contain charset field, according do RFC 8259
See original GitHub issueDescribe the bug
According to RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format content-type application/json
does not have any charset defined, as it must be utf-8 encoded. Older specifications allowed other unicode encodings, and parsers were detecting exact encoding used by first four bytes, still not by charset param.
Axios defaults to header Content-Type: application/json;charset=utf-8
for some types of sent data.
This breaks some HTTP servers and applications, who are not recognizing the content-type.
To Reproduce
axios.post("http://example.com", {an: "object"});
// Content-Type: application/json;charset=utf-8 header will be set
Expected behavior
Content-Type: application/json
header should be set as default for object data, without charset parameter.
Environment:
- Axios Version - 0.18.0, I’ve also checked master branch source - it is still there. https://github.com/axios/axios/blob/b4c5d35d2875191dfa8c3919d4227dce8e2ad23f/lib/defaults.js#L52
Additional context/Screenshots This breaks some parts of the rabbitmq-management API.
Related issues: https://github.com/axios/axios/issues/859
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (2 by maintainers)
Top GitHub Comments
@chinesedfan where in RFC7231 is charset parameter defined for application/json? It’s not, because parameter names are defined for concrete media-types in appropriate RFCs.
charset
parameter is neither declared for all headers nor for all media-types.application/json
media-type does not have “charset” parameter defined.From RFC7231
See IANA media type registry for
application/json
: https://www.iana.org/assignments/media-types/application/jsonAnd compare to
plain/html
entry which hascharset
parameter explicitly defined: https://www.iana.org/assignments/media-types/text/htmlWe should try mend this in 0.20.0 I will look at the pull request.