有没有办法在中间件中获取响应内容?以下代码是从此处复制的。
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
Run Code Online (Sandbox Code Playgroud)