add "charset=utf-8" to content-type "application/json"

See original GitHub issue

The Request.prototype.json function sets Content-Type headers to application/json. utf-8 really should be the default imo, and this lead me to several hours of debugging hell to realize that the API I was working with rejects all but UTF-8 json.

I made these changes:

main.js, Line #803:

this.setHeader('content-type', 'application/json; charset=utf-8')

main.js, Line #807:

this.setHeader('content-type', 'application/json; charset=utf-8')

Is there anything wrong with this? Any thoughts?

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Reactions:11
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
kevinoidcommented, May 25, 2013

Section 3 of RFC 4627 defines how the charset is detected using the first 4 bytes of the file, which is why it does not define a charset parameter. Adding a charset parameter is contrary to the standard because the standard defines the set of parameters for the media type and their interpretation and it does not include a charset parameter (Section 6).

6reactions
thesmartcommented, May 26, 2013

It’s ok, Tim Berners-Lee couldn’t affect this thread.

Vote however you want.

Smart

On May 25, 2013, at 6:52 PM, Kevin Locke notifications@github.com wrote:

That document discusses the charset parameter for media types “that are of type text, such as text/html, text/plain, etc.”. JSON is of type application, for which the charset parameter is not defined. HTTP 1.1, as defined in RFC 2616 defines the Content-Type as being a media type, as defined in the IANA registry. application/json is so defined and does not include a charset parameter. No HTTP RFC that I am aware of adds a charset parameter to all media types.

Which of the message bus API implementations incorrectly decode JSON as non-Unicode types?

— Reply to this email directly or view it on GitHub.

Read more comments on GitHub >

github_iconTop Results From Across the Web

application/json; charset=utf-8" really mean? - Stack Overflow
Content -type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding is ...
Read more >
Akka Http how to add charset utf-8 to the content-type header
I dont find how to set the content type to "application/json; charset=UTF-8" with the completeOKWithFuture and Jackson marshaller.
Read more >
How to make sure "content-type: application/json; charset=utf ...
When I run a HTTP Call, I get a JSON response, but the first line is always "content-type: application/json; charset=utf-8" (as shown below) ......
Read more >
Why did I get "Error 400: CTGLA2001E : Invalid request ... - IBM
To fix the problem, all you need to do is to add "Content-Type: application/json; charset=UTF-8" at the header of the HTTP POST request....
Read more >
"application/json; charset=utf-8" not supported - aerogear-dev
... is based on AFNetworking 121 When doing my login request in iOS I bumped into the issue of having content type set...
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