Fixed #21483 -- Added WSGI environ to kwargs sent to request_started signal.

This commit is contained in:
Joshua "jag" Ginsberg 2013-11-20 20:03:02 -05:00 committed by Tim Graham
parent 149605dfb4
commit eb2af16c59
6 changed files with 16 additions and 3 deletions

View File

@ -176,7 +176,7 @@ class WSGIHandler(base.BaseHandler):
raise
set_script_prefix(get_script_name(environ))
signals.request_started.send(sender=self.__class__)
signals.request_started.send(sender=self.__class__, environ=environ)
try:
request = self.request_class(environ)
except UnicodeDecodeError:

View File

@ -1,5 +1,5 @@
from django.dispatch import Signal
request_started = Signal()
request_started = Signal(providing_args=["environ"])
request_finished = Signal()
got_request_exception = Signal(providing_args=["request"])

View File

@ -98,7 +98,7 @@ class ClientHandler(BaseHandler):
self.load_middleware()
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 = WSGIRequest(environ)
# sneaky little hack so that we can easily get round

View File

@ -589,6 +589,12 @@ Arguments sent with this signal:
``sender``
The handler class -- e.g. ``django.core.handlers.wsgi.WsgiHandler`` -- that
handled the request.
``environ``
The ``environ`` dictionary provided to the request.
.. versionchanged:: 1.8
The ``environ`` argument was added.
request_finished
----------------

View File

@ -256,6 +256,10 @@ Signals
:meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
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
^^^^^^^^^

View File

@ -114,6 +114,7 @@ class SignalsTests(TestCase):
def setUp(self):
self.signals = []
self.signaled_environ = None
request_started.connect(self.register_started)
request_finished.connect(self.register_finished)
@ -123,6 +124,7 @@ class SignalsTests(TestCase):
def register_started(self, **kwargs):
self.signals.append('started')
self.signaled_environ = kwargs.get('environ')
def register_finished(self, **kwargs):
self.signals.append('finished')
@ -131,6 +133,7 @@ class SignalsTests(TestCase):
response = self.client.get('/regular/')
self.assertEqual(self.signals, ['started', 'finished'])
self.assertEqual(response.content, b"regular content")
self.assertEqual(self.signaled_environ, response.wsgi_request.environ)
def test_request_signals_streaming_response(self):
response = self.client.get('/streaming/')