diff --git a/django/http/response.py b/django/http/response.py index aaebefe022b..822589fe816 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -317,7 +317,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 1679b6e036e..4ee342c2521 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -385,6 +385,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,',