Git Product home page Git Product logo

nancy.leakybucket's Introduction

Nancy.LeakyBucket

A request limiter based on the Leaky Bucket algorithm

Build status Coverage Status NuGet

This package is available via install the NuGet:

Install-Package Nancy.LeakyBucket

Then, you can enable LeakyBucket rate limiting by enabling the LeakyBucketRateLimiter in your Bootstrapper class:

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
    {
        LeakyBucketRateLimiter.Enable(pipelines, new LeakyBucketRateLimiterConfiguration
        {
            MaxNumberOfRequests = 100,
            RefreshRate = TimeSpan.FromSeconds(1)
        });

        base.ApplicationStartup(container, pipelines);
    }
}

How it works

  1. When a request comes in it will extract the IClientIdentifier from the NancyContext with the function specified in the configuration.
  2. It will check for any requests that have passed the specified RefreshRate and remove them from the IRequestStore.
  3. It will then add the new request to the IRequestStore.
  4. It will check how many requests are remaining.
  5. If it exceeds the MaxNumberOfRequests then it will return a 429 Too Many Requests status code, otherwise it will continue on with the request.

Configuration

The 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.

The 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.

nancy.leakybucket's People

Contributors

mrstebo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

azkoss hopla

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.