/// <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)); }
public ThrottleContext(HttpContext httpContext, ThrottleStrategy strategy, IThrottleCounterStore store) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (strategy == null) { throw new ArgumentNullException(nameof(strategy)); } HttpContext = httpContext; Requirements = strategy.Policy.Requirements; Exclusions = strategy.Policy.Exclusions; RouteTemplate = strategy.RouteTemplate; _pendingRequirements = new HashSet <IThrottleRequirement>(Requirements); Store = store; }
public virtual async Task <ThrottleContext> EvaluateAsync(HttpContext httpContext, ThrottleStrategy strategy) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (strategy == null) { throw new ArgumentNullException(nameof(strategy)); } var throttleContext = new ThrottleContext(httpContext, strategy, _store); foreach (var exclusion in _exclusionHandlers) { await exclusion.HandleExclusionAsync(throttleContext); } if (!throttleContext.HasAborted) { foreach (var handler in _handlers) { await handler.HandleRequirementAsync(throttleContext); } } return(throttleContext); }