I wanted to get the response body in a middleware in FastAPI. I tried the method by using the following answer on stackoverflow:
https://stackoverflow.com/a/71883126/19869027
But When I use the following code in the middleware, response_body = [section async for section in response.body_iterator]
it blocks the background tasks I use in fastapi routes, and response is not generated till background task finishes. It works fine if I remove middleware.
Kindly suggest some solution. Regards