Is there any way to get raw response in middleware?
E.g.
app = FastAPI()
@app.get("/any/route")
async def make_dummy_response():
return [1,2,3]
In my case, middleware is good for processing all responses, but it need to decompress body response, that's produce an overhead.
How can I get raw return for all routes?
In this case is list object.
Definitely, I can use a decorator, but they have to be added for each route which is inconvenient.
Middleware look like this
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
response = await call_next(request)
# overhead
response_body = [chunk async for chunk in response.body_iterator]
response.body_iterator = iterate_in_threadpool(iter(response_body))