You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
632 B
20 lines
632 B
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Tiobon.Core.Https;
|
|
|
|
namespace Tiobon.Core.Extensions.Middlewares;
|
|
|
|
public static class FluentResponseBodyMiddleware
|
|
{
|
|
public static IApplicationBuilder UseResponseBodyRead(this IApplicationBuilder app)
|
|
{
|
|
return app.Use(async (context, next) =>
|
|
{
|
|
await using var swapStream = new FluentHttpResponseStream(context!.Features!.Get<IHttpResponseBodyFeature>()!,
|
|
context!.Features!.Get<IHttpBodyControlFeature>()!);
|
|
context.Response.Body = swapStream;
|
|
await next(context);
|
|
context.Response.Body.Seek(0, SeekOrigin.Begin);
|
|
});
|
|
}
|
|
} |