Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#23949 closed Cleanup/optimization (invalid)

Add charset to JsonResponse

Reported by: Torsten Bronger Owned by: nobody
Component: HTTP handling Version: 1.7
Severity: Normal Keywords:
Cc: bronger@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Please change the default content-type of JSON responses from "application/json" to "application/json; charset=ascii" or "application/json; charset=utf-8". The way Django generates the JSON, it's guaranteed to work with both values of charset. HTTP itself doesn't define a default charset for application/* types AFAIK.

Change History (6)

comment:1 by Aymeric Augustin, 9 years ago

Can you clarify why this change is needed?

comment:2 by Torsten Bronger, 9 years ago

Because I like don't like ambiguity, I overrode the content_type parameter in order to have a charset. But it would be nice if I needn't do this anymore in an upcoming Django version. It is a cosmetical problem I admit. The HTTP standard only states a default charset for text/* (namely 8859-1), so a client has to guess in case of application/* and in absence of charset, so I think it is good habit to make it explicit. Besides, there are no disadvantages, and it is a simple change.

comment:3 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

According to RFC 7159, "No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients."

See also the same report in flask which was closed as invalid.

comment:4 by Tom Christie, 9 years ago

Confirming tim's resolution. JSON responses in REST framework also don't include the charset, for the same reason.

comment:5 by Serhiy, 8 years ago

What do you think about defaulting to UTF-8? Right now it's ASCII, AFAIU. While the RFC clearly recommends UTF. Should I bother opening new ticket for this?

comment:6 by Tim Graham, 8 years ago

I believe it defaults to settings.DEFAULT_CHARSET which is 'utf-8' by default.

Note: See TracTickets for help on using tickets.
Back to Top