Beispiel #1
0
        public ThrottleStrategy GetThrottleStrategy(HttpContext httpContext, ThrottleOptions options)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

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

            foreach (var route in _routes)
            {
                if (route.TryMatch(httpContext.Request))
                {
                    return(new ThrottleStrategy
                    {
                        Policy = route.GetPolicy(httpContext.Request, options),
                        RouteTemplate = route.RouteTemplate
                    });
                }
            }

            return(null);
        }
        public ThrottlePolicy Build(ThrottleOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(new ThrottlePolicy(Requirements, Exclusions, _policyName));
        }
        /// <summary>
        /// Creates a new instance of <see cref="DefaultThrottleStrategyProvider"/>.
        /// </summary>
        /// <param name="options">The options configured for the application.</param>
        public DefaultThrottleStrategyProvider(IOptions <ThrottleOptions> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options.Value;
        }
Beispiel #4
0
        public ThrottlePolicy Build(ThrottleOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(_policy);
        }
Beispiel #5
0
        public ThrottleService(
            ILoggerFactory loggerFactory,
            IEnumerable <IRequirementHandler> handlers,
            IEnumerable <IExclusionHandler> exclusionHandlers,
            ISystemClock clock,
            IThrottleCounterStore store,
            IOptions <ThrottleOptions> options,
            ConfigureOptions <ThrottleOptions> configureOptions = null)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

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

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

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

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

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

            _options = options.Value;
            if (configureOptions != null)
            {
                configureOptions.Configure(_options);
            }

            _options.BuildPolicies();

            _handlers          = handlers.ToArray();
            _exclusionHandlers = exclusionHandlers.ToArray();
            _logger            = loggerFactory.CreateLogger <ThrottleService>();
            _clock             = clock;
            _store             = store;
        }
        /// <summary>
        /// Instantiates a new <see cref="T:ThrottleMiddleware" />.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="throttleService">An instance of <see cref="T:IThrottleService" />.</param>
        /// <param name="policy">An instance of the <see cref="T:ThrottlePolicy" /> which can be applied.</param>
        public ThrottleMiddleware(
            RequestDelegate next,
            ILoggerFactory loggerFactory,
            IThrottleService throttleService,
            IThrottleStrategyProvider strategyProvider,
            ISystemClock clock,
            IOptions <ThrottleOptions> options,
            ConfigureOptions <ThrottleOptions> configureOptions)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

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

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

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

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

            _next             = next;
            _logger           = loggerFactory.CreateLogger <ThrottleMiddleware>();
            _throttleService  = throttleService;
            _strategyProvider = strategyProvider;
            _clock            = clock;
            _options          = options.Value;

            if (configureOptions != null)
            {
                configureOptions.Configure(_options);
            }
        }
        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));
        }
Beispiel #8
0
 public abstract ThrottlePolicy GetPolicy(HttpRequest httpContext, ThrottleOptions options);