question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content-type header for application/json should not contain charset field, according do RFC 8259

See original GitHub issue

Describe 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:

Additional context/Screenshots This breaks some parts of the rabbitmq-management API.

Related issues: https://github.com/axios/axios/issues/859

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
OJezucommented, Feb 26, 2020

@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

The presence or absence of a parameter might be significant to the processing of a media-type, depending on its definition within the media type registry.

See IANA media type registry for application/json: https://www.iana.org/assignments/media-types/application/json

And compare to plain/html entry which has charset parameter explicitly defined: https://www.iana.org/assignments/media-types/text/html

0reactions
jasonsaaymancommented, Apr 27, 2020

We should try mend this in 0.20.0 I will look at the pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content-type header for application/json should not contain ...
According to RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format content-type application/json does not have any charset defined, as it ......
Read more >
application/json; charset=utf-8" really mean? - Stack Overflow
The header just denotes what the content is encoded in. It is not necessarily possible to deduce the type of the content from...
Read more >
Make default charset UTF-8 when using `receiveText` for ...
Request with Content-Type: application/json is decoded not as UTF-8, while request with Content-Type: application/json; charset=utf-8 is decoded correctly.
Read more >
OData JSON Format Version 4.01 - OASIS Open
Requests and responses with a JSON message body MUST have a Content-Type header value of application/json. Requests MAY add the charset parameter to...
Read more >
Media Types - Internet Assigned Numbers Authority
[RFC2046] specifies that Media Types (formerly known as MIME types) and Media Subtypes will be assigned and listed by the IANA.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found