public async Task Invoke(HttpContext httpContext) { // compute identity from request var identity = SetIdentity(httpContext); var key = ComputeCounterKey(identity); var canProcess = true; lock (lockObj) { canProcess = _handler.Acquire(key, _options.Total, _options.PerSencond); } if (canProcess) { await _next.Invoke(httpContext); return; } httpContext.Response.StatusCode = 429; await httpContext.Response.WriteAsync("up to limit"); await _next.Invoke(httpContext); }