Skip to content

Middleware to apply limits to an ASP.NET Core pipeline, ported from Damian Hickey's OWIN LimitsMiddleware

License

Notifications You must be signed in to change notification settings

lvermeulen/LimitsMiddleware.aspnetcore

Repository files navigation

Icon

Limits Middleware for ASP.NET Core Build status license NuGet Coverage Status Join the chat at https://gitter.im/lvermeulen/LimitsMiddleware.aspnetcore

Middleware to apply limits to an ASP.NET Core pipeline. This code was ported from Damian Hickey's Limits Middleware for Owin.

Features:

  • Max bandwidth
  • Max concurrent requests
  • Connection timeout
  • Max query string
  • Max request content length
  • Max url length
  • Min response delay

Usage:

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(..);
		}
    }
}

Thanks

About

Middleware to apply limits to an ASP.NET Core pipeline, ported from Damian Hickey's OWIN LimitsMiddleware

Resources

License

Stars

Watchers

Forks

Packages