Created
April 22, 2019 04:30
-
-
Save ffantasy/e1095529672925e61a1242cb15a6dd7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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