コード例 #1
0
        static IpRateLimit()
        {
            if (Setting.Configuration?.IpRateLimiting == null)
            {
                return;
            }

            Logger = Factory.Logger.Value;

            Options = Setting.Configuration.IpRateLimiting;

            Policies = Setting.Configuration.IpRateLimitPolicies;

            IpParser = new ReversProxyIpParser(Options.RealIpHeader);

            MemoryCache = Factory.MemoryCache.Value;

            var rateLimitCounterStore = Factory.RateLimitCounterStore.Value;

            var ipPolicyStore = new MemoryCacheIpPolicyStore(MemoryCache, Options, Policies);

            Processor = new IpRateLimitProcessor(Options, rateLimitCounterStore, ipPolicyStore, IpParser);

            Configurationed = true;
        }
コード例 #2
0
 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);
 }