コード例 #1
0
 public LeakyBucketContainer(
     IRequestStore requestStore,
     LeakyBucketContainerConfiguration configuration,
     ISystemClock systemClock = null)
 {
     _requestStore  = requestStore ?? throw new ArgumentNullException(nameof(requestStore));
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _systemClock   = systemClock ?? new SystemClock();
 }
コード例 #2
0
        public override async Task Invoke(IOwinContext context)
        {
            var identifier = _configuration.ClientIdentifierFunc(context);
            var store      = _configuration.RequestStore;
            var config     = new LeakyBucketContainerConfiguration
            {
                RefreshRate = _configuration.RefreshRate,
                Limit       = _configuration.MaxNumberOfRequests
            };
            var container = new LeakyBucketContainer(store, config);

            if (container.RequestsRemaining(identifier) <= 0)
            {
                context.Response.StatusCode = ExtendedHttpStatusCodes.TooManyRequests;
            }

            await Next.Invoke(context);
        }