Common code shared between ThrottlingHandler and ThrottlingFilter
示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class.
 /// By default, the <see cref="QuotaExceededResponseCode"/> property
 /// is set to 429 (Too Many Requests).
 /// </summary>
 public ThrottlingMiddleware(OwinMiddleware next)
     : base(next)
 {
     QuotaExceededResponseCode = (HttpStatusCode)429;
     Repository = new CacheRepository();
     core       = new ThrottlingCore();
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime.
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        /// <param name="ipAddressParser">
        /// The IpAddressParser
        /// </param>
        public ThrottlingMiddleware(OwinMiddleware next,
                                    ThrottlePolicy policy,
                                    IPolicyRepository policyRepository,
                                    IThrottleRepository repository,
                                    IThrottleLogger logger,
                                    IIpAddressParser ipAddressParser)
            : base(next)
        {
            core            = new ThrottlingCore();
            core.Repository = repository;
            Repository      = repository;
            Logger          = logger;

            if (ipAddressParser != null)
            {
                core.IpAddressParser = ipAddressParser;
            }

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy           = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime. 
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        /// <param name="ipAddressParser">
        /// The IpAddressParser
        /// </param>
        public ThrottlingMiddleware(OwinMiddleware next, 
            ThrottlePolicy policy, 
            IPolicyRepository policyRepository, 
            IThrottleRepository repository, 
            IThrottleLogger logger,
            IIpAddressParser ipAddressParser)
            : base(next)
        {
            core = new ThrottlingCore();
            core.Repository = repository;
            Repository = repository;
            Logger = logger;

            if (ipAddressParser != null)
            {
                core.IpAddressParser = ipAddressParser;
            }

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class. 
 /// By default, the <see cref="QuotaExceededResponseCode"/> property 
 /// is set to 429 (Too Many Requests).
 /// </summary>
 public ThrottlingMiddleware(OwinMiddleware next)
     : base(next)
 {
     QuotaExceededResponseCode = (HttpStatusCode)429;
     Repository = new CacheRepository();
     core = new ThrottlingCore();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingHandler"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime.
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        /// <param name="ipAddressParser">
        /// The IpAddressParser
        /// </param>
        public ThrottlingHandler(ThrottlePolicy policy,
                                 IPolicyRepository policyRepository,
                                 IThrottleRepository repository,
                                 IThrottleLogger logger,
                                 IIpAddressParser ipAddressParser = null)
        {
            core = new ThrottlingCore
            {
                Repository = repository
            };
            Repository = repository;
            Logger     = logger;

            if (ipAddressParser != null)
            {
                core.IpAddressParser = ipAddressParser;
            }

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.Policy           = policy;
            this.PolicyRepository = policyRepository;

            policyRepository?.Save(ThrottleManager.GetPolicyKey(), policy);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingFilter"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime.
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        public ThrottlingFilter(ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger)
        {
            core            = new ThrottlingCore();
            core.Repository = repository;
            Repository      = repository;
            Logger          = logger;

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy           = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingFilter"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime. 
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        public ThrottlingFilter(ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger)
        {
            core = new ThrottlingCore();
            core.Repository = repository;
            Repository = repository;
            Logger = logger;

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
        public HttpModuleThrottlingHandler(ThrottlePolicy policy,
                                           IPolicyRepository policyRepository,
                                           IThrottleRepository repository,
                                           IIpAddressParser ipAddressParser = null)
        {
            core            = new ThrottlingCore();
            core.Repository = repository;
            Repository      = repository;

            if (ipAddressParser != null)
            {
                core.IpAddressParser = ipAddressParser;
            }

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy           = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrottlingFilter"/> class.
 /// By default, the <see cref="QuotaExceededResponseCode"/> property
 /// is set to 429 (Too Many Requests).
 /// </summary>
 public ThrottlingFilter()
 {
     QuotaExceededResponseCode = (HttpStatusCode)429;
     Repository = new CacheRepository();
     core       = new ThrottlingCore();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrottlingFilter"/> class.
 /// By default, the <see cref="QuotaExceededResponseCode"/> property 
 /// is set to 429 (Too Many Requests).
 /// </summary>
 public ThrottlingFilter()
 {
     QuotaExceededResponseCode = (HttpStatusCode)429;
     Repository = new CacheRepository();
     core = new ThrottlingCore();
 }
 public HttpModuleThrottlingHandler()
 {
     QuotaExceededResponseCode = (HttpStatusCode)429;
     Repository = new CacheRepository();
     core       = new ThrottlingCore();
 }