Is there a way to perform logic on the body of a response in a custom middleware? For example if the response contains some value then add that value to a header on the response. I know the BaseHTTPMiddleware class returns a StreamingResponse instead of a regular one so I’m not sure how this would be achieved.
did you find a solution for that?
FYI, there seems to be various issues open on the Starlette repo discussing this issue already:
Current tl;dr seems to be that there’s no way to read the body inside a middleware, and that it is by design. (Not taking positions on whether this is the right approach, though.)