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(); }
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); }