diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 426679c..47f111d 100644
a
|
b
|
import codecs
|
4 | 4 | import logging |
5 | 5 | import sys |
6 | 6 | from io import BytesIO |
| 7 | from functools import partial |
7 | 8 | from threading import Lock |
8 | 9 | |
9 | 10 | from django import http |
… |
… |
class WSGIHandler(base.BaseHandler):
|
254 | 255 | else: |
255 | 256 | response = self.get_response(request) |
256 | 257 | finally: |
257 | | signals.request_finished.send(sender=self.__class__) |
| 258 | cb = partial(signals.request_finished.send, sender=self.__class__) |
| 259 | response._on_close_callbacks.append(cb) |
258 | 260 | |
259 | 261 | try: |
260 | 262 | status_text = STATUS_CODE_TEXT[response.status_code] |
diff --git a/django/http/response.py b/django/http/response.py
index df0a955..e294fda 100644
a
|
b
|
class HttpResponseBase(six.Iterator):
|
40 | 40 | self._headers = {} |
41 | 41 | self._charset = settings.DEFAULT_CHARSET |
42 | 42 | self._closable_objects = [] |
| 43 | self._on_close_callbacks = [] |
43 | 44 | if mimetype: |
44 | 45 | warnings.warn("Using mimetype keyword argument is deprecated, use" |
45 | 46 | " content_type instead", PendingDeprecationWarning) |
… |
… |
class HttpResponseBase(six.Iterator):
|
226 | 227 | def close(self): |
227 | 228 | for closable in self._closable_objects: |
228 | 229 | closable.close() |
| 230 | for callback in self._on_close_callbacks: |
| 231 | callback() |
229 | 232 | |
230 | 233 | def write(self, content): |
231 | 234 | raise Exception("This %s instance is not writable" % self.__class__.__name__) |