static Func<IHttpRequest, Task<HttpResponse>> Wrap(Func<IHttpRequest, Task<HttpResponse>> handler, LeakyBucket rateLimitBucket) { return request => rateLimitBucket.Fill(1) ? handler(request) : Task.FromResult(TooManyRequests); }
RateLimitedEndpoint(Method method, Route route, Func<IHttpRequest, Task<HttpResponse>> handler, LeakyBucket rateLimitBucket) : base(method, route, Wrap(handler, rateLimitBucket)) { this.rateLimitBucket = rateLimitBucket; }