1
0
mirror of https://github.com/django/django.git synced 2025-10-28 16:16:12 +00:00

Fixed #25725 -- Made HttpReponse immediately close objects.

This commit is contained in:
Johannes Hoppe
2015-11-11 20:17:32 +01:00
committed by Tim Graham
parent a6c803a2e3
commit 5233b70070
5 changed files with 29 additions and 18 deletions

View File

@@ -316,13 +316,16 @@ class HttpResponse(HttpResponseBase):
def content(self, value):
# Consume iterators upon assignment to allow repeated iteration.
if hasattr(value, '__iter__') and not isinstance(value, (bytes, six.string_types)):
content = b''.join(self.make_bytes(chunk) for chunk in value)
if hasattr(value, 'close'):
self._closable_objects.append(value)
value = b''.join(self.make_bytes(chunk) for chunk in value)
try:
value.close()
except Exception:
pass
else:
value = self.make_bytes(value)
content = self.make_bytes(value)
# Create a list of properly encoded bytestrings to support write().
self._container = [value]
self._container = [content]
def __iter__(self):
return iter(self._container)