Created
October 6, 2025 09:37
-
-
Save uzbekdev1/8a0699f4f65f303f7961a6d03e26ea7f to your computer and use it in GitHub Desktop.
request buffering
This file contains hidden or 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 GlobalMiddleware | |
| { | |
| private readonly RequestDelegate _next; | |
| private string _requestBody; | |
| public GlobalMiddleware(RequestDelegate next) | |
| { | |
| _next = next; | |
| } | |
| public async Task Invoke(HttpContext context) | |
| { | |
| if (context.Request.Method == "PUT" || context.Request.Method == "POST"|| context.Request.Method == "PATCH") | |
| { | |
| context.Request.EnableBuffering(); | |
| _requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); | |
| context.Request.Body.Position = 0; | |
| } | |
| await _next(context); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment