Reading response body in middleware
See original GitHub issueI would like to write every response to a log before returning it.
I tried to accomplish this using middleware. However, the call_next
method returns a StreamingResponse
. When I read it using the same code as in StreamingResponse.__call__
, the response obviously can’t be sent to the client anymore.
Is there any way to accomplish what I’m trying to do?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to read ASP.NET Core Response.Body? - Stack Overflow
The solution requires swapping out Response.Body with a MemoryStream while reading the stream into a string variable, then swapping it back ...
Read more >Reading HttpContext.ResponseBody in custom middleware
Hello, I'm attempting to write a custom middleware that reads both the request and response body from the http context and logs them....
Read more >Request and Response operations in ASP.NET Core
This article explains how to read from the request body and write to the response body. Code for these operations might be required...
Read more >C# – How to read ASP.NET Core Response.Body - iTecNote
The solution requires swapping out Response.Body with a MemoryStream while reading the stream into a string variable, then swapping it back before sending...
Read more >Read Request and Response body in ASP.NET Core
Here I am making use of filters to log my request and response size by overriding OnResultExecuted() method. Please note that middleware in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was super easy, thanks a lot!
Thanks for the help here everyone! 👏 🙇
Thanks for reporting back and closing the issue 👍