question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading response body in middleware

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aseipelcommented, Oct 15, 2019

This was super easy, thanks a lot!

0reactions
tiangolocommented, Apr 10, 2020

Thanks for the help here everyone! 👏 🙇

Thanks for reporting back and closing the issue 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found