#21620 closed Bug (duplicate)
HttpResponseBase._convert_to_charset STILL complains about newline it inserted itself
Reported by: | poly | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As reported in #20889, a header that is so long will be splitted by email.header.Header into several lines. And tim fixed it here.
However, when the length of the header exceeds certain limit, email.header.Header still inserts newlines, which raises the great BadHeaderError.
FYI:
# coding=utf-8 from django.http import HttpResponse h = HttpResponse() f = '\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91'.decode('utf-8') h['Content-Disposition'] = u'attachment; filename="%s"' % f
This snippet works when tim's patch is applied, but the next doesn't
# coding=utf-8 from django.http import HttpResponse h = HttpResponse() f = '\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91'.decode('utf-8') h['Content-Disposition'] = u'attachment; filename="%s"' % f
As you can see, the only difference is that the second one has a longer header value.
Also, I'm wondering why we need to encode those headers in the mime way, since most browsers don't support them(at least chrome), why can't we just encode them in latin1 like what flask does.
Thanks for your time.
Hi,
In order to keep the discussion in one place, can you reopen #20889 instead?
Thanks.