From 03b13c6ddf8d40bf6dbee895cb6f739e3ab015c9 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 17 Nov 2017 12:13:40 +0100 Subject: [PATCH] Rephrase middleware intro (#2526) The old intro still explained middleware using the deprecated factories. --- docs/web.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/web.rst b/docs/web.rst index b42104d77ac..9d3639c5d58 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -990,14 +990,7 @@ Middlewares :mod:`aiohttp.web` provides a powerful mechanism for customizing :ref:`request handlers` via *middlewares*. -*Middlewares* are setup by providing a sequence of *middleware factories* to -the keyword-only ``middlewares`` parameter when creating an -:class:`Application`:: - - app = web.Application(middlewares=[middleware_factory_1, - middleware_factory_2]) - -A *middleware* is just a coroutine that can modify either the request or +A *middleware* is a coroutine that can modify either the request or response. For example, here's a simple *middleware* which appends ``' wink'`` to the response:: @@ -1014,6 +1007,12 @@ response. For example, here's a simple *middleware* which appends Every *middleware* should accept two parameters, a :class:`request ` instance and a *handler*, and return the response. +When creating an :class:`Application`, these *middlewares* are passed to +the keyword-only ``middlewares`` parameter:: + + app = web.Application(middlewares=[middleware_1, + middleware_2]) + Internally, a single :ref:`request handler ` is constructed by applying the middleware chain to the original handler in reverse order, and is called by the :class:`RequestHandler` as a regular *handler*.