{"id":18710616,"url":"https://github.com/mrstebo/nancy.leakybucket","last_synced_at":"2025-04-12T11:33:37.483Z","repository":{"id":46043206,"uuid":"97024709","full_name":"mrstebo/Nancy.LeakyBucket","owner":"mrstebo","description":"A request limiter based on the Leaky Bucket algorithm","archived":false,"fork":false,"pushed_at":"2021-11-18T06:22:43.000Z","size":26,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T06:22:05.814Z","etag":null,"topics":["bucket","hacktoberfest","leaky","leaky-bucket-algorithm","leakybucket","limiter","limiting","nancy","rate","rate-limiter","rate-limiting"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrstebo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-12T15:38:24.000Z","updated_at":"2022-04-16T02:11:42.000Z","dependencies_parsed_at":"2022-09-09T02:50:15.216Z","dependency_job_id":null,"html_url":"https://github.com/mrstebo/Nancy.LeakyBucket","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrstebo%2FNancy.LeakyBucket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrstebo%2FNancy.LeakyBucket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrstebo%2FNancy.LeakyBucket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrstebo%2FNancy.LeakyBucket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrstebo","download_url":"https://codeload.github.com/mrstebo/Nancy.LeakyBucket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560427,"owners_count":21124653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bucket","hacktoberfest","leaky","leaky-bucket-algorithm","leakybucket","limiter","limiting","nancy","rate","rate-limiter","rate-limiting"],"created_at":"2024-11-07T12:35:02.836Z","updated_at":"2025-04-12T11:33:37.418Z","avatar_url":"https://github.com/mrstebo.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nancy.LeakyBucket\nA request limiter based on the Leaky Bucket algorithm\n\n[![Build status](https://ci.appveyor.com/api/projects/status/nc82bmu7i0ac7cpf/branch/master?svg=true)](https://ci.appveyor.com/project/mrstebo/nancy-leakybucket/branch/master)\n[![Coverage Status](https://coveralls.io/repos/github/mrstebo/Nancy.LeakyBucket/badge.svg?branch=master)](https://coveralls.io/github/mrstebo/Nancy.LeakyBucket?branch=master)\n[![NuGet](http://img.shields.io/nuget/v/Nancy.LeakyBucket.svg?style=flat)](https://www.nuget.org/packages/Nancy.LeakyBucket/)\n\nThis package is available via install the [NuGet](https://www.nuget.org/packages/Nancy.LeakyBucket):\n\n```powershell\nInstall-Package Nancy.LeakyBucket\n```\n\nThen, you can enable LeakyBucket rate limiting by enabling the `LeakyBucketRateLimiter` in your `Bootstrapper` class:\n\n```cs\npublic class Bootstrapper : DefaultNancyBootstrapper\n{\n    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)\n    {\n        LeakyBucketRateLimiter.Enable(pipelines, new LeakyBucketRateLimiterConfiguration\n        {\n            MaxNumberOfRequests = 100,\n            RefreshRate = TimeSpan.FromSeconds(1)\n        });\n\n        base.ApplicationStartup(container, pipelines);\n    }\n}\n```\n\n## How it works\n\n1. When a request comes in it will extract the `IClientIdentifier` from the `NancyContext` with the function specified in the configuration.\n2. It will check for any requests that have passed the specified `RefreshRate` and remove them from the `IRequestStore`.\n3. It will then add the new request to the `IRequestStore`.\n4. It will check how many requests are remaining.\n5. If it exceeds the `MaxNumberOfRequests` then it will return a **429 Too Many Requests** status code, otherwise it will continue on with the request.\n\n\n## Configuration\n\nThe `LeakyBucketRateLimiterConfiguration` can specifiy an `IRequestStore`, that is set to the `DefaultRequestStore` by default, which is responsible for holding the current number of requests for each client.\n\nThe `LeakyBucketRateLimiterConfiguration` can specifies a function that determines what a client is. By default it creates a `DefaultClientIdentifier` that holds a reference to the remote address.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrstebo%2Fnancy.leakybucket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrstebo%2Fnancy.leakybucket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrstebo%2Fnancy.leakybucket/lists"}