Middleware to apply limits to an ASP.NET Core pipeline. This code was ported from Damian Hickey's Limits Middleware for Owin.
- Max bandwidth
- Max concurrent requests
- Connection timeout
- Max query string
- Max request content length
- Max url length
- Min response delay
Configuration values can be supplied as constants or with a delegate for runtime values.
public class Startup
{
public void Configure(IApplicationBuilder app)
{
// static settings
app
.MaxBandwidth(10000) //bps
.MaxConcurrentRequests(10)
.ConnectionTimeout(TimeSpan.FromSeconds(10))
.MaxQueryStringLength(15) //Unescaped QueryString
.MaxRequestContentLength(15)
.MaxUrlLength(20)
.MinResponseDelay(200ms)
.Use(..);
// dynamic settings
app
.MaxBandwidth(() => 10000) //bps
.MaxConcurrentRequests(() => 10)
.ConnectionTimeout(() => TimeSpan.FromSeconds(10))
.MaxQueryStringLength(() => 15)
.MaxRequestContentLength(() => 15)
.MaxUrlLength(() => 20)
.Use(..);
}
}
}
- Funnel icon by Arthur Shlain from The Noun Project