﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24598	JsonResponse loses encoding support in Content-Type header	Curtis Maloney	nobody	"By default when a content_type is not passed to `HttpResponse` it will create one from `settings.DEFAULT_CONTENT_TYPE`, and attach the encoding.

So, when unspecified, the header will appear as:

{{{
Content-Type: text/html; encoding=utf-8
}}}

However, if you specify the `content_type`, this action is not taken.

That's understandable in a ""consenting adults"" context, however the `JsonResponse` sets `content_type` using `kwargs.setdefault`, thus forcing the loss of encoding annotation in all responses.

I propose instead that `HttpResponseBase` check for a `default_content_type` property to override `settings.DEFAULT_CONTENT_TYPE`, thus:


{{{
#!diff
diff --git a/django/http/response.py b/django/http/response.py
index c8d6930..40186b5 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -54,8 +54,8 @@ class HttpResponseBase(six.Iterator):
         self._reason_phrase = reason
         self._charset = charset
         if content_type is None:
-            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
-                                               self.charset)
+            content_type = getattr(self, 'default_content_type', settings.DEFAULT_CONTENT_TYPE)
+            content_type = '%s; charset=%s' % (content_type, self.charset)
         self['Content-Type'] = content_type
}}}
"	Bug	closed	HTTP handling	1.8	Normal	duplicate			Unreviewed	1	1	1	0	0	0
