Skip to content

Instantly share code, notes, and snippets.

@ffantasy
Created April 22, 2019 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffantasy/e1095529672925e61a1242cb15a6dd7e to your computer and use it in GitHub Desktop.
Save ffantasy/e1095529672925e61a1242cb15a6dd7e to your computer and use it in GitHub Desktop.
public class EditResponseMiddleware
{
private readonly RequestDelegate _next;
public EditResponseMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
var originBody = context.Response.Body;
var newBody = new MemoryStream();
context.Response.Body = newBody;
await _next(context);
newBody.Seek(0, SeekOrigin.Begin);
string json = new StreamReader(newBody).ReadToEnd();
context.Response.Body = originBody;
await context.Response.WriteAsync("modifiedJson");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment