From 2c08d474a83b438cf02595c6854f2f79e708b852 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 24 Aug 2013 18:08:05 +0200 Subject: [PATCH] [1.6.x] Fixed #20961 -- Fixed HttpResponse default empty content Thanks epandurski at gmail.com for the report. Backport of f4e980456 from master. --- django/http/response.py | 2 +- tests/httpwrappers/tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/http/response.py b/django/http/response.py index 8d8db2c8b4..f522c0684b 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -323,7 +323,7 @@ class HttpResponse(HttpResponseBase): streaming = False - def __init__(self, content='', *args, **kwargs): + def __init__(self, content=b'', *args, **kwargs): super(HttpResponse, self).__init__(*args, **kwargs) # Content is a bytestring. See the `content` property methods. self.content = content diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index c4c7996aa5..8e0c415623 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -398,6 +398,13 @@ class HttpResponseTests(unittest.TestCase): self.assertEqual(r.tell(), 6) self.assertEqual(r.content, b'abcdef') + # with Content-Encoding header + r = HttpResponse() + r['Content-Encoding'] = 'winning' + r.write(b'abc') + r.write(b'def') + self.assertEqual(r.content, b'abcdef') + def test_unsafe_redirect(self): bad_urls = [ 'data:text/html,',