﻿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
21282	The serialize_headers method of HttpResponse fails to handle latin1-compatible values	Raphaël Barrois	nobody	"If a header value (passed as unicode) contains only ascii data, `serialize_headers()` doesn't fail
If it contains characters that can't be encoded in latin1, `serialize_headers()` doesn't fail
If it contains only characters valid in latin1, including some outside the ascii range, `serialize_headers()` fails with a `UnicodeDecodeError`.

The culprit seems to lie on line 132 of `django/http/response.py`: that line calls `('%s: %s' % (key, value)).encode('us-ascii')`, but at this point, key is ascii bytes and value is a bytes array containing either latin1-encoded text or mime-encoded utf8 text.

Since we're using `unicode_literals`, Python tries `value.decode('ascii')`, which fails if, and only if, value contains latin1 characters outside the ascii range.

I have attached a patch containing both a test exhibiting the issue and a patch fixing it (no test failure).

Note: This is not a release blocker, since the `serialize_headers()` and its callers (`serialize()` and `__str__()`) aren't used while answering requests."	Bug	closed	HTTP handling	1.4	Normal	fixed	http header encoding		Accepted	1	0	0	0	0	0
