From 92220134990b841ed1aa5ef39b564f99215a9ff5 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 20 Oct 2015 23:27:16 -0400 Subject: [PATCH] Improve documentation for signals - Fix 2 typos - Show how to attach signal --- docs/web.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/web.rst b/docs/web.rst index 4a79256b424..143962b8ca4 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -606,7 +606,7 @@ Signals .. versionadded:: 0.18 -While :ref:`midlewares ` gives very powerful +While :ref:`middlewares ` gives very powerful tool for customizing :ref:`web handler` processing we need another machinery also called signals. @@ -614,11 +614,14 @@ For example middleware may change HTTP headers for *unprepared* response only (see :meth:`aiohttp.web.StreamResponse.prepare`). But sometimes we need a hook for changing HTTP headers for streamed -responses and websockets. That can be done by subsribing on +responses and websockets. That can be done by subscribing on :attr:`aiohttp.web.Application.on_response_prepare` signal:: - async def on_prepare(request, response): - response.headers['My-Header'] = 'value' + async def on_prepare(request, response): + response.headers['My-Header'] = 'value' + + app.on_response_prepare.append(on_prepare) + Signal handlers should not return a value but may modify incoming mutable parameters.