1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #13222 -- Made HttpResponse iterable once

response.content can be accessed many times as desired, and always
returns the same result.

iter(response) works only once and consumes the iterator.
This commit is contained in:
Aymeric Augustin
2012-10-24 11:33:56 +02:00
parent 495a8b8107
commit 82b3e6ffcb
3 changed files with 30 additions and 4 deletions

View File

@@ -596,7 +596,11 @@ class TransactionTestCase(SimpleTestCase):
msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code))
text = force_text(text, encoding=response._charset)
content = b''.join(response).decode(response._charset)
if response.streaming:
content = b''.join(response.streaming_content)
else:
content = response.content
content = content.decode(response._charset)
# Avoid ResourceWarning about unclosed files.
response.close()
if html: