public MyIpRateLimitMiddleware(RequestDelegate next
                                , IOptions <IpRateLimitOptions> options
                                , IRateLimitCounterStore counterStore
                                , IIpPolicyStore policyStore
                                , IRateLimitConfiguration config
                                , ILogger <IpRateLimitMiddleware> logger)
     : base(next, options, counterStore, policyStore, config, logger)
 {
 }
Example #2
0
 public IpRateLimitMiddleware(RequestDelegate next,
                              IOptions <IpRateLimitOptions> options,
                              IRateLimitCounterStore counterStore,
                              IIpPolicyStore policyStore,
                              IRateLimitConfiguration config,
                              ILogger <IpRateLimitMiddleware> logger)
     : base(next, options?.Value, new IpRateLimitProcessor(options?.Value, counterStore, policyStore, config), config)
 {
     _logger = logger;
 }
Example #3
0
 public IpRateLimitProcessor(
     IpRateLimitOptions options,
     IRateLimitCounterStore counterStore,
     IIpPolicyStore policyStore,
     IRateLimitConfiguration config)
     : base(options, counterStore, new IpCounterKeyBuilder(options), config)
 {
     _options     = options;
     _policyStore = policyStore;
 }
Example #4
0
        public IpRateLimitMiddleware(RequestDelegate next,
                                     IRateLimitLoader Loader,
                                     IRateLimitCounterStore counterStore,
                                     IIpPolicyStore policyStore,
                                     IRateLimitConfiguration config,
                                     ILogger <IpRateLimitMiddleware> logger)
            : base(next, Loader.GetIpRateLimitOptions(), new IpRateLimitProcessor(Loader.GetIpRateLimitOptions(), counterStore, policyStore, config), config)

        {
            _logger = logger;
        }
 public IpRateLimitMiddleware(RequestDelegate next,
                              IOptions <IpRateLimitOptions> options,
                              IRateLimitCounterStore counterStore,
                              IIpPolicyStore policyStore,
                              ILogger <IpRateLimitMiddleware> logger)
 {
     _next      = next;
     _options   = options.Value;
     _logger    = logger;
     _processor = new IpRateLimitProcessor(_options, counterStore, policyStore);
 }
Example #6
0
 public IpRateLimitProcessor(
     IpRateLimitOptions options,
     IIpPolicyStore policyStore,
     IProcessingStrategy processingStrategy)
     : base(options)
 {
     _options            = options;
     _policyStore        = policyStore;
     _counterKeyBuilder  = new IpCounterKeyBuilder(options);
     _processingStrategy = processingStrategy;
 }
Example #7
0
 public CustomIpRateLimitMiddleware(
     RequestDelegate next,
     IOptions <IpRateLimitOptions> options,
     IRateLimitCounterStore counterStore,
     IIpPolicyStore policyStore,
     ILogger <IpRateLimitMiddleware> logger,
     IIpAddressParser ipParser = null
     ) : base(next, options, counterStore, policyStore, logger, ipParser)
 {
     _options = options.Value;
 }
 public CustomRateLimitingMiddleware(RequestDelegate next,
                                     IProcessingStrategy processingStrategy,
                                     IOptions <IpRateLimitOptions> options,
                                     IRateLimitCounterStore counterStore,
                                     IIpPolicyStore policyStore,
                                     IRateLimitConfiguration config,
                                     ILogger <IpRateLimitMiddleware> logger)
     : base(next, processingStrategy, options, counterStore, policyStore, config, logger)
 {
     _rateLimitOptions = options.Value;
 }
Example #9
0
        public IpRateLimitProcessor(IpRateLimitOptions options,
                                    IRateLimitCounterStore counterStore,
                                    IIpPolicyStore policyStore,
                                    IIpAddressParser ipParser)
        {
            _options      = options;
            _counterStore = counterStore;
            _policyStore  = policyStore;
            _ipParser     = ipParser;

            _core = new RateLimitCore(true, options, _counterStore);
        }
        public IpRateLimitMiddleware(RequestDelegate next,
                                     IOptions <IpRateLimitOptions> options,
                                     IRateLimitCounterStore counterStore,
                                     IIpPolicyStore policyStore,
                                     ILogger <IpRateLimitMiddleware> logger,
                                     IIpAddressParser ipParser = null)
        {
            _next     = next;
            _options  = options.Value;
            _logger   = logger;
            _ipParser = ipParser ?? new ReversProxyIpParser(_options.RealIpHeader);

            _processor = new IpRateLimitProcessor(_options, counterStore, policyStore, _ipParser);
        }
 public MyIPRateMiddleware(
     RequestDelegate next,
     IOptions <IpRateLimitOptions> options,
     IRateLimitCounterStore counterStore,
     IIpPolicyStore policyStore,
     ILogger <IpRateLimitMiddleware> logger,
     IIpAddressParser ipParser = null)
 {
     this._next      = next;
     this._options   = options.Value;
     this._logger    = logger;
     this._ipParser  = ipParser != null ? ipParser : (IIpAddressParser) new ReversProxyIpParser(this._options.RealIpHeader);
     this._processor = new IpRateLimitProcessor(this._options, counterStore, policyStore, this._ipParser);
 }
Example #12
0
        public IpRateLimitMiddleware(RequestDelegate next,
                                     IOptions <IpRateLimitOptions> options,
                                     IRateLimitCounterStore counterStore,
                                     IIpPolicyStore policyStore,
                                     IRateLimitConfiguration config,
                                     ILogger <IpRateLimitMiddleware> logger)
            : base(next, options?.Value, new IpRateLimitProcessor(options?.Value, counterStore, policyStore, config), config)

        {
            _logger        = logger;
            _ipParser      = ipParser != null ? ipParser : new ReversProxyIpParser(_options.RealIpHeader);
            _ipPolicyStore = policyStore;

            _processor = new IpRateLimitProcessor(_options, counterStore, policyStore, _ipParser);
        }
 public CustomIpRateLimitMiddleware(
     IMemoryCache memoryCache,
     IBlockIpService blockIpService,
     RequestDelegate next,
     IOptions <IpRateLimitOptions> options,
     IRateLimitCounterStore counterStore,
     IIpPolicyStore policyStore,
     ILogger <IpRateLimitMiddleware> logger,
     IIpAddressParser ipParser = null)
     : base(next, options, counterStore, policyStore, logger, ipParser)
 {
     _memoryCache    = memoryCache;
     _blockIpService = blockIpService;
     _options        = options.Value;
     _logger         = logger;
 }
Example #14
0
 public CustomIpRateLimitMiddleware(
     IDistributedCache distributedCache,
     IBlockIpService blockIpService,
     RequestDelegate next,
     IProcessingStrategy processingStrategy,
     IRateLimitConfiguration rateLimitConfiguration,
     IOptions <IpRateLimitOptions> options,
     IIpPolicyStore policyStore,
     ILogger <CustomIpRateLimitMiddleware> logger)
     : base(next, processingStrategy, options, policyStore, rateLimitConfiguration, logger)
 {
     _distributedCache = distributedCache;
     _blockIpService   = blockIpService;
     _options          = options.Value;
     _logger           = logger;
 }
 public CustomIpRateLimitMiddleware(
     IMemoryCache memoryCache,
     IBlockIpService blockIpService,
     RequestDelegate next,
     IOptions<IpRateLimitOptions> options,
     IRateLimitCounterStore counterStore,
     IIpPolicyStore policyStore,
     ILogger<IpRateLimitMiddleware> logger,
     IIpAddressParser ipParser = null)
     : base(next, options, counterStore, policyStore, logger, ipParser)
 {
     _memoryCache = memoryCache;
     _blockIpService = blockIpService;
     _options = options.Value;
     _logger = logger;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottleMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next.</param>
        /// <param name="options">The options.</param>
        /// <param name="counterStore">The counter store.</param>
        /// <param name="policyStore">The policy store.</param>
        /// <param name="config">The rate limit configuration.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="configuration">The API configuration.</param>
        /// <param name="serializer">The JSON serializer.</param>
        /// <exception cref="ArgumentNullException">configuration</exception>
        public ThrottleMiddleware(
            RequestDelegate next,
            IOptions <IpRateLimitOptions> options,
            IRateLimitCounterStore counterStore,
            IIpPolicyStore policyStore,
            IRateLimitConfiguration config,
            ILogger <IpRateLimitMiddleware> logger,
            IApiConfiguration configuration,
            IDefaultJsonSerializer serializer)
            : base(next, options, counterStore, policyStore, config, logger)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            if (options.Value == null)
            {
                throw new UnexpectedNullException("The options value is null.");
            }

            this.options       = options.Value;
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this.serializer    = serializer ?? throw new ArgumentNullException(nameof(serializer));
        }
 public IpRateLimitController(IOptions <IpRateLimitOptions> optionsAccessor, IIpPolicyStore ipPolicyStore)
 {
     _options       = optionsAccessor.Value;
     _ipPolicyStore = ipPolicyStore;
 }
 public IpRateLimitSeedStartupService(IIpPolicyStore ipPolicyStore, IClientPolicyStore clientPolicyStore)
 {
     _ipPolicyStore     = ipPolicyStore;
     _clientPolicyStore = clientPolicyStore;
 }
Example #19
0
 public IpRateLimitMiddleware(RequestDelegate next, IProcessingStrategy processingStrategy, Microsoft.Extensions.Options.IOptions <IpRateLimitOptions> options, IRateLimitCounterStore counterStore, IIpPolicyStore policyStore, IRateLimitConfiguration config, ILogger <IpRateLimitMiddleware> logger)
     : base(next, (RateLimitOptions)(options?.Value), new IpRateLimitProcessor(options?.Value, counterStore, policyStore, config, processingStrategy), config)
 {
     _logger = logger;
 }
Example #20
0
 public ParametersManagerController(ParametersManager parametersManager, IOptions <IpRateLimitOptions> rateLimitOptions, IIpPolicyStore ipPolicyStore)
 {
     _parametersManager = parametersManager;
     _rateLimitOptions  = rateLimitOptions.Value;
     _ipPolicyStore     = ipPolicyStore;
 }
        public CustomIpRateLimitMiddleware(RequestDelegate next, IOptions <IpRateLimitOptions> options, IRateLimitCounterStore counterStore, IIpPolicyStore policyStore, ILogger <IpRateLimitMiddleware> logger, IIpAddressParser ipParser = null)
            : base(next, options, counterStore, policyStore, logger, ipParser)
        {
            if (String.IsNullOrWhiteSpace(options.Value.QuotaExceededMessage))
            {
                throw new InvalidOperationException("API quota exceeded message not set in the config.");
            }

            if (options.Value.HttpStatusCode == default(int))
            {
                throw new InvalidOperationException("API quota exceeded status code message not set in the config.");
            }

            if (String.IsNullOrWhiteSpace(options.Value.RealIpHeader))
            {
                throw new InvalidOperationException("API real IP header value not set in the config.");
            }

            quotaExceededMessage = options.Value.QuotaExceededMessage;
            httpStatusCode       = options.Value.HttpStatusCode;
            ipAddressParser      = ipParser != null ? ipParser : new ReversProxyIpParser(options.Value.RealIpHeader);
        }