summaryrefslogtreecommitdiff
path: root/django/http
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2020-02-07 11:30:26 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-11 20:39:12 +0100
commit549445519ce90cc5c1e3f981853cc0c67725f3ed (patch)
tree5f670b4c20c613df35e1803040569b42153422e7 /django/http
parente3f6e18513224c8ad081e5a19da641f49b0b43da (diff)
downloaddjango-549445519ce90cc5c1e3f981853cc0c67725f3ed.tar.gz
Reverted "Fixed #30565 -- Closed HttpResponse when wsgi.file_wrapper closes file-like object."
This reverts commit cce47ff65a4dd3786c049ec14ee889e128ca7de9.
Diffstat (limited to 'django/http')
-rw-r--r--django/http/response.py28
1 files changed, 0 insertions, 28 deletions
diff --git a/django/http/response.py b/django/http/response.py
index 596732a5b8..a7d98117a6 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -242,9 +242,6 @@ class HttpResponseBase:
# The WSGI server must call this method upon completion of the request.
# See http://blog.dscpl.com.au/2012/10/obligations-for-calling-close-on.html
- # When wsgi.file_wrapper is used, the WSGI server instead calls close()
- # on the file-like object. Django ensures this method is called in this
- # case by replacing self.file_to_stream.close() with a wrapped version.
def close(self):
for closable in self._closable_objects:
try:
@@ -401,39 +398,14 @@ class FileResponse(StreamingHttpResponse):
self.filename = filename
super().__init__(*args, **kwargs)
- def _wrap_file_to_stream_close(self, filelike):
- """
- Wrap the file-like close() with a version that calls
- FileResponse.close().
- """
- closing = False
- filelike_close = getattr(filelike, 'close', lambda: None)
-
- def file_wrapper_close():
- nonlocal closing
- # Prevent an infinite loop since FileResponse.close() tries to
- # close the objects in self._closable_objects.
- if closing:
- return
- closing = True
- try:
- filelike_close()
- finally:
- self.close()
-
- filelike.close = file_wrapper_close
-
def _set_streaming_content(self, value):
if not hasattr(value, 'read'):
self.file_to_stream = None
return super()._set_streaming_content(value)
self.file_to_stream = filelike = value
- # Add to closable objects before wrapping close(), since the filelike
- # might not have close().
if hasattr(filelike, 'close'):
self._closable_objects.append(filelike)
- self._wrap_file_to_stream_close(filelike)
value = iter(lambda: filelike.read(self.block_size), b'')
self.set_headers(filelike)
super()._set_streaming_content(value)