#13391: Detect charset from Content-type header in the HttpResponse
---------------------------+------------------------------------------------
 Reporter:  lucky          |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  HTTP handling  |     Version:  SVN       
 Keywords:  HttpResponse   |       Stage:  Unreviewed
Has_patch:  1              |  
---------------------------+------------------------------------------------
 I was surprised today to realize that Django must be configured to
 instantiate django.http.HttpResponse object.
 {{{
 Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
 [GCC 4.4.1] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> from django.http import HttpResponse
 >>> response = HttpResponse("Hello, World!", content_type="text/plain;
 charset=iso-8859-1")
 Traceback (most recent call last):
    ...
 ImportError: Settings cannot be imported, because environment variable
 DJANGO_SETTINGS_MODULE is undefined.
 }}}
 This happens because {{{HttpResponse.__init__}}} reads
 {{{settings.DEFAULT_CHARSET}}} to fill the property {{{self._charset}}}.
 It is assumed charset of the response content. This is always taken from
 the settings even if {{{content_type}}} has passed as parameter and
 contains the {{{charset}}}.

 In addition, this behavior breaks the
 
[http://code.djangoproject.com/browser/django/trunk/django/test/testcases.py#L362
 django.test.TestCase.assertContains()] when encoding of response content
 differs from the {{{settings.DEFAULT_CHARSET}}}.

 This patch makes HttpResponse object to fill {{{self._charset}}} property
 with value from content_type argument if given.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to