Questions about middlewares
See original GitHub issueI’d like to do a very simple task, that is add a middleware which runs before the endpoints and adds a few properties to the request object. Very similar to how authentication middleware does it, but I’d like to make it more flexible.
My aim is to have something like this:
- request.user_.user_data
- request.user_.org_data
- request.user_.allowed_regions for example
Now, my problem is the following:
- BaseHTTPMiddleware in the docs starts with
response = await call_next(request)
and it adds a Header after the request has been processed. How can I use BaseHTTPMiddleware to add processing before an endpoint runs? - Can I add custom properties to the request object in a Middleware?
- In case I cannot do it with BaseHTTPMiddleware I’m confused about the pure ASGI 2 vs. 3. middlewares. All the examples in starlette 0.11.4 are on ASGI 2, but ProxyHeadersMiddleware from uvicorn github is ASGI 3, do I understand it right?
- I get a
INFO: ASGI 'lifespan' protocol appears unsupported.
if I try to add something based on the skeleton of ProxyHeadersMiddleware. Will it disappear if I upgrade to 0.12.beta?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
20 Middleware Interview Questions and Answers - CLIMB
1. What is a middleware? · 2. Can you give me some examples of middleware in the context of web development? · 3....
Read more >26 Middleware Interview Questions and Answers
26 Middleware Questions and Answers: ; 1 :: What is garbage collection and what is it used for? ; 2 :: What is...
Read more >Top 13 Layering & Middleware Interview Questions And ...
Top 13 Layering & Middleware Interview Questions · eustjWhy is it a good idea for “lower” application layers not to be aware of...
Read more >14 questions with answers in MIDDLEWARE | Science topic
Review and cite MIDDLEWARE protocol, troubleshooting and other methodology information | Contact experts in MIDDLEWARE to get answers.
Read more >Middleware Administrator Interview Questions - AmbitionBox
Middleware Administrator Interview Questions · Q1. How to implement circular and linear logging in WMQ? · Q2. How to create and configure Queue ......
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
OK, I’ve been able to make some progress trying to write my ASGI middleware for 0.12.
My problem is that if I add a
request.json()
line in the middleware, then it cannot be called in the view. When the view calls it, it stalls the app and uvicorn need to be force quitted (Waiting for connections to close. (CTRL+C to force quit)
).How can I solve this (or maybe this is a bug?).
There’s a bunch of different things being asked here, so I’m going to close this off as a general discussion rather than a narrowed-down actionable requested change.