/// <inheritdoc />
        public virtual Task <ThrottleStrategy> GetThrottleStrategyAsync(HttpContext httpContext, string policyName, IThrottleRouter fallbackRouter)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            ThrottlePolicy policy;

            if (policyName != null)
            {
                policy = _options.GetPolicy(policyName);
                if (policy != null)
                {
                    return(Task.FromResult(new ThrottleStrategy {
                        Policy = policy, RouteTemplate = "{*any}"
                    }));
                }
            }

            ThrottleStrategy strategy = _options.Routes.GetThrottleStrategy(httpContext, _options);

            if (strategy == null)
            {
                strategy = fallbackRouter?.GetThrottleStrategy(httpContext, _options);
            }

            return(Task.FromResult(strategy));
        }
Beispiel #2
0
        public ThrottlePolicy Build(ThrottleOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(options.GetPolicy(_policyName));
        }
        public override ThrottlePolicy GetPolicy(HttpRequest httpContext, ThrottleOptions options)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(options.GetPolicy(_policyName));
        }