Skip to content

Commit

Permalink
Move reversing slice of middleware apps into the cache (#9170)
Browse files Browse the repository at this point in the history
(cherry picked from commit eacf2e0)
  • Loading branch information
bdraco committed Sep 18, 2024
1 parent b15c895 commit 91fc2c0
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 91fc2c0

Please sign in to comment.