from fastapi import FastAPI, Request app = FastAPI() @app.middleware('http') async def add_header(request: Request, call_next): resp = await call_next(request) resp.headers['X-App'] = 'demo' return resp