Fixed #21483 -- Added WSGI environ to kwargs sent to request_started signal.
This commit is contained in:
parent
149605dfb4
commit
eb2af16c59
|
@ -176,7 +176,7 @@ class WSGIHandler(base.BaseHandler):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
set_script_prefix(get_script_name(environ))
|
set_script_prefix(get_script_name(environ))
|
||||||
signals.request_started.send(sender=self.__class__)
|
signals.request_started.send(sender=self.__class__, environ=environ)
|
||||||
try:
|
try:
|
||||||
request = self.request_class(environ)
|
request = self.request_class(environ)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
request_started = Signal()
|
request_started = Signal(providing_args=["environ"])
|
||||||
request_finished = Signal()
|
request_finished = Signal()
|
||||||
got_request_exception = Signal(providing_args=["request"])
|
got_request_exception = Signal(providing_args=["request"])
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ClientHandler(BaseHandler):
|
||||||
self.load_middleware()
|
self.load_middleware()
|
||||||
|
|
||||||
request_started.disconnect(close_old_connections)
|
request_started.disconnect(close_old_connections)
|
||||||
request_started.send(sender=self.__class__)
|
request_started.send(sender=self.__class__, environ=environ)
|
||||||
request_started.connect(close_old_connections)
|
request_started.connect(close_old_connections)
|
||||||
request = WSGIRequest(environ)
|
request = WSGIRequest(environ)
|
||||||
# sneaky little hack so that we can easily get round
|
# sneaky little hack so that we can easily get round
|
||||||
|
|
|
@ -589,6 +589,12 @@ Arguments sent with this signal:
|
||||||
``sender``
|
``sender``
|
||||||
The handler class -- e.g. ``django.core.handlers.wsgi.WsgiHandler`` -- that
|
The handler class -- e.g. ``django.core.handlers.wsgi.WsgiHandler`` -- that
|
||||||
handled the request.
|
handled the request.
|
||||||
|
``environ``
|
||||||
|
The ``environ`` dictionary provided to the request.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.8
|
||||||
|
|
||||||
|
The ``environ`` argument was added.
|
||||||
|
|
||||||
request_finished
|
request_finished
|
||||||
----------------
|
----------------
|
||||||
|
|
|
@ -256,6 +256,10 @@ Signals
|
||||||
:meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
|
:meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
|
||||||
their traceback attached as a ``__traceback__`` attribute.
|
their traceback attached as a ``__traceback__`` attribute.
|
||||||
|
|
||||||
|
* The ``environ`` argument, which contains the WSGI environment structure from
|
||||||
|
the request, was added to the :data:`~django.core.signals.request_started`
|
||||||
|
signal.
|
||||||
|
|
||||||
Templates
|
Templates
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,7 @@ class SignalsTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.signals = []
|
self.signals = []
|
||||||
|
self.signaled_environ = None
|
||||||
request_started.connect(self.register_started)
|
request_started.connect(self.register_started)
|
||||||
request_finished.connect(self.register_finished)
|
request_finished.connect(self.register_finished)
|
||||||
|
|
||||||
|
@ -123,6 +124,7 @@ class SignalsTests(TestCase):
|
||||||
|
|
||||||
def register_started(self, **kwargs):
|
def register_started(self, **kwargs):
|
||||||
self.signals.append('started')
|
self.signals.append('started')
|
||||||
|
self.signaled_environ = kwargs.get('environ')
|
||||||
|
|
||||||
def register_finished(self, **kwargs):
|
def register_finished(self, **kwargs):
|
||||||
self.signals.append('finished')
|
self.signals.append('finished')
|
||||||
|
@ -131,6 +133,7 @@ class SignalsTests(TestCase):
|
||||||
response = self.client.get('/regular/')
|
response = self.client.get('/regular/')
|
||||||
self.assertEqual(self.signals, ['started', 'finished'])
|
self.assertEqual(self.signals, ['started', 'finished'])
|
||||||
self.assertEqual(response.content, b"regular content")
|
self.assertEqual(response.content, b"regular content")
|
||||||
|
self.assertEqual(self.signaled_environ, response.wsgi_request.environ)
|
||||||
|
|
||||||
def test_request_signals_streaming_response(self):
|
def test_request_signals_streaming_response(self):
|
||||||
response = self.client.get('/streaming/')
|
response = self.client.get('/streaming/')
|
||||||
|
|
Loading…
Reference in New Issue