/// <summary> /// Enable throttling. /// </summary> /// <returns></returns> public static IApplicationBuilder UseThrottling(this IApplicationBuilder app, Action <ThrottleRouteBuilder> configureRoutes) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (configureRoutes == null) { throw new ArgumentNullException(nameof(configureRoutes)); } var builder = new ThrottleRouteBuilder(); configureRoutes(builder); Action <ThrottleOptions> configure; configure = o => { o.Routes = builder.Build(); }; return(app.UseMiddleware <ThrottleMiddleware>(new ConfigureOptions <ThrottleOptions>(configure))); }
//public static void ApplyPolicy(this ThrottleRouteBuilder router, string httpMethod, string routeTemplate, ThrottlePolicy policy) //{ // router.ApplyPolicy(new[] { httpMethod }, routeTemplate, policy); //} //public static void ApplyPolicy(this ThrottleRouteBuilder router, string httpMethod, string routeTemplate, string policyName, Action<ThrottlePolicyBuilder> configurePolicy) //{ // router.ApplyPolicy(new[] { httpMethod }, routeTemplate, policyName, configurePolicy); //} //public static void ApplyPolicy(this ThrottleRouteBuilder router, string httpMethod, string routeTemplate, string policyName) //{ // router.ApplyPolicy(new[] { httpMethod }, routeTemplate, policyName); //} //public static void ApplyPolicy(this ThrottleRouteBuilder router, string routeTemplate, ThrottlePolicy policy) //{ // router.ApplyPolicy((IEnumerable<string>)null, routeTemplate, policy); //} public static void ApplyPolicy(this ThrottleRouteBuilder router, string routeTemplate, string policyName) { router.AddRoute(EmptyHttpMethods, routeTemplate, policyName); }
//public static void ApplyPolicy(this ThrottleRouteBuilder router, IEnumerable<string> httpMethods, string routeTemplate, string policyName, Action<ThrottlePolicyBuilder> configurePolicy) //{ // var policyBuilder = new ThrottlePolicyBuilder(policyName); // configurePolicy(policyBuilder); // router.AddRoute(httpMethods, routeTemplate, policyBuilder.Build()); //} public static void AddRoute(this ThrottleRouteBuilder router, IEnumerable <string> httpMethods, string routeTemplate, string policyName) { router.Add(new NamedThrottleRoute(httpMethods, routeTemplate, policyName)); }