Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21483 -- Added WSGI environ to kwargs sent to request_started …

…signal.
  • Loading branch information...
commit eb2af16c59c3014541e2ad8ca63e510bc076dd8b 1 parent 149605d
Joshua "jag" Ginsberg j00bar authored timgraham committed
2  django/core/handlers/wsgi.py
View
@@ -176,7 +176,7 @@ def __call__(self, environ, start_response):
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:
2  django/core/signals.py
View
@@ -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"])
2  django/test/client.py
View
@@ -98,7 +98,7 @@ def __call__(self, environ):
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
6 docs/ref/signals.txt
View
@@ -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
----------------
4 docs/releases/1.8.txt
View
@@ -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
^^^^^^^^^
3  tests/handlers/tests.py
View
@@ -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 @@ def tearDown(self):
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 @@ def test_request_signals(self):
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/')
Please sign in to comment.
Something went wrong with that request. Please try again.