Iceshrimp.NET/Iceshrimp.Backend/Core/Middleware/RequestBufferingMiddleware.cs
Laura Hausmann 705e061f74
[backend/asp] Refactor middleware stack
This commit splits the request pipeline conditionally instead of invoking every middleware in the stack.

It also simplifies middleware instantiation by using runtime discovery, allowing for Plugins to add Middleware.
2024-11-18 19:02:44 +01:00

22 lines
No EOL
624 B
C#

using Iceshrimp.Backend.Core.Extensions;
using JetBrains.Annotations;
namespace Iceshrimp.Backend.Core.Middleware;
[UsedImplicitly]
public class RequestBufferingMiddleware(RequestDelegate next) : ConditionalMiddleware<EnableRequestBufferingAttribute>
{
[UsedImplicitly]
public async Task InvokeAsync(HttpContext ctx)
{
var attr = GetAttributeOrFail(ctx);
ctx.Request.EnableBuffering(attr.MaxLength);
await next(ctx);
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class EnableRequestBufferingAttribute(long maxLength) : Attribute
{
internal readonly long MaxLength = maxLength;
}