Skip to content

Commit

Permalink
[PR #9170/eacf2e0 backport][3.10] Move reversing slice of middleware …
Browse files Browse the repository at this point in the history
…apps into the cache (#9186)
  • Loading branch information
bdraco authored Sep 18, 2024
1 parent df0f28b commit 31c0753
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/9170.misc.rst
4 changes: 2 additions & 2 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _build_middlewares(
handler: Handler, apps: Tuple["Application", ...]
) -> Callable[[Request], Awaitable[StreamResponse]]:
"""Apply middlewares to handler."""
for app in apps:
for app in apps[::-1]:
for m, _ in app._middlewares_handlers: # type: ignore[union-attr]
handler = update_wrapper(partial(m, handler=handler), handler) # type: ignore[misc]
return handler
Expand Down Expand Up @@ -545,7 +545,7 @@ async def _handle(self, request: Request) -> StreamResponse:

if self._run_middlewares:
if not self._has_legacy_middlewares:
handler = _build_middlewares(handler, match_info.apps[::-1])
handler = _build_middlewares(handler, match_info.apps)
else:
for app in match_info.apps[::-1]:
for m, new_style in app._middlewares_handlers: # type: ignore[union-attr]
Expand Down

0 comments on commit 31c0753

Please sign in to comment.