summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJohannes Hoppe <info@johanneshoppe.com>2015-11-11 20:17:32 +0100
committerTim Graham <timograham@gmail.com>2015-12-14 12:46:48 -0500
commit5233b70070f8979f41ca1da2c1b1d78c8e30944e (patch)
tree54993a920bb9df5cdfbbc92dc4fbb010a1d662a5 /django
parenta6c803a2e3d270818d20f3f0c76e2241de9f0ab1 (diff)
Fixed #25725 -- Made HttpReponse immediately close objects.
Diffstat (limited to 'django')
-rw-r--r--django/http/response.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/django/http/response.py b/django/http/response.py
index 94d14ddb54..da9f9ef6a6 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -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)