[Django] #23949: Add charset to JsonResponse

37 views
Skip to first unread message

Django

unread,
Dec 2, 2014, 3:20:06 PM12/2/14
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
--------------------------------------+--------------------
Reporter: bronger | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23949>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 2, 2014, 3:39:57 PM12/2/14
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.7
Component: HTTP handling | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can you clarify why this change is needed?

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:1>

Django

unread,
Dec 2, 2014, 3:52:34 PM12/2/14
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.7
Component: HTTP handling | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by bronger):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:2>

Django

unread,
Dec 6, 2014, 11:48:50 AM12/6/14
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.7
Component: HTTP handling | Resolution: invalid

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => invalid


Comment:

According to [http://tools.ietf.org/html/rfc7159#page-11 RFC 7159], "No
"charset" parameter is defined for this registration. Adding one really
has no effect on compliant recipients."

See also [https://github.com/mitsuhiko/flask/issues/454 the same report in
flask] which was closed as invalid.

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:3>

Django

unread,
Dec 7, 2014, 2:54:44 AM12/7/14
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version: 1.7
Component: HTTP handling | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by tomchristie):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:4>

Django

unread,
Jan 14, 2016, 2:13:53 PM1/14/16
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: HTTP handling | Version: 1.7
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by int-ua):

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:5>

Django

unread,
Jan 14, 2016, 7:42:18 PM1/14/16
to django-...@googlegroups.com
#23949: Add charset to JsonResponse
-------------------------------------+-------------------------------------
Reporter: bronger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: HTTP handling | Version: 1.7
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/23949#comment:6>

Reply all
Reply to author
Forward
0 new messages