pierrejeambrun opened a new pull request, #48678:
URL: https://github.com/apache/airflow/pull/48678

   This add support for registering root middlewares from plugins.
   
   Plugins subapplication can have their on Middleware define there but this 
will not operates on the root application requests. (Requests outside of the 
plugins).
   
   For multiple reasons it can be interesting to have the ability to register 
root middlewares from plugins, for instance to manipulate headers, responses, 
or requests accross the entire application.
   
   For instance I can inject a custom script on the `index.html` page:
   ```python
   class InjectIndexAlertMiddleware(BaseHTTPMiddleware):
       async def dispatch(self, request, call_next):
           response = await call_next(request)
   
           url = request.url
           if url == conf.get("api", "base_url"):
               response = 
StreamingResponse(inject_script(response.body_iterator), media_type="text/html")
           return response
           
       fastapi_root_middlewares = [
           {
               "middleware": InjectIndexAlertMiddleware,
               "args": [],
               "kwargs": {},
               "name": "Inject Alert Middleware",
           }
       ]
   ```
   ![Screenshot 2025-04-02 at 14 11 
24](https://github.com/user-attachments/assets/98a42506-17df-476a-ab49-df753e286fec)
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to