A new idea about BaseHTTPMiddleware #2654
Unanswered
abersheeran
asked this question in
Ideas
Replies: 1 comment 4 replies
-
Part of the complexity also comes from handing over control to the user's code and having to pass them a callback. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/abersheeran/baize/blob/master/baize/asgi/middleware.py
Recently I needed to use a design similar to BaseHTTPMiddleware in WSGI, so I spent a whole day today adjusting baize and successfully implemented a version that meets my needs.
As far as I know, a considerable part of the complex design of BaseHTTPMiddleware comes from the reading of the request body, but reading the request body in the middleware itself is a niche behavior. We should encourage people who need to read the request body to directly write Prue ASGI middleware, abandoning very few requirements, and we can make BaseHTTPMiddleware more usable and easier to maintain to meet the needs of most people.
So I made a version in baize.asgi.middleware, where users are not allowed to read the request body in the middleware, and I found that everything became simple.
I wonder what you think of this design? @Kludex @adriangb
Beta Was this translation helpful? Give feedback.
All reactions