, , .Net Core 2.2
, MemoryStream, . , , IIS . , Azure, .
:
DeChunkerMiddleware {private readonly RequestDelegate _next;
public DeChunkerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
try
{
if (context.Request.Method != "OPTIONS")
{
var originalBodyStream = context.Response.Body;
using (var responseBody = new MemoryStream())
{
context.Response.Body = responseBody;
long length = 0;
context.Response.OnStarting(() =>
{
context.Response.Headers.ContentLength = length;
return Task.CompletedTask;
});
await _next(context);
length = context.Response.Body.Length;
context.Response.Body.Seek(0, SeekOrigin.Begin);
await responseBody.CopyToAsync(originalBodyStream);
}
}
else
{
await _next(context);
}
}
catch (Exception)
{
}
}
}
Startup:
app.UseMiddleware<DeChunkerMiddleware>();
app.UseMvC().