[Document] Order of middlewares
See original GitHub issueI just started a project with starlette awesome, and found a small issue about the docs related on the order of execution of middlewares… My case, is so usual, like in django:
auth_middleware that depends on session_middleware
Seems like the order is inverse on the order you declare them:
app.add_middleware(AuthenticationMiddleware, backend=middlewares.AuthBackend())
app.add_middleware(middlewares.SessionMiddleware)
The session one is executed first but needs to be added later. I’m not against it, it’s an onion, and can be seen in both directions… But I thought that at least should be documented.
On the API side, perhaps is a nice idea, to just instantiate them on a single call, like:
app.add_middlewares([
middlewareX, middlewareY # in order of execution... (at least when the request is entering..)
])
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does order matter in a middleware file? - Stack Overflow
Order matters in middleware because middleware functions are executed in a sequence and you'd need to execute one before the other in order...
Read more >Writing middleware for use in Express apps
The order of middleware loading is important: middleware functions that are loaded first are also executed first. If myLogger is loaded after the...
Read more >Order of middleware | Mastering ASP.NET Web API
The pictorial representation of request processing describes the execution order of middleware. The sequence order is created by placement of the Use ,...
Read more >ASP.NET Core Middleware | Microsoft Learn
The order that middleware components are added in the Program.cs file defines the order in which the middleware components are invoked on ...
Read more >Document middleware order - Caddy Community
Document middleware order ... For debugging uses especially considering the increasing 3rd party middlewares coming with the new site it might ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
had the same issue, just adding some documentation would be great as this is a pretty opaque bug to fix.
I think this was achieved in Version 0.13.0. From the current docs:
So this can be closed now.