LeakyBucket.Owin 1.0.0

Description

There is a newer version of this package available.
See the version list below for details.
Install-Package LeakyBucket.Owin -Version 1.0.0
dotnet add package LeakyBucket.Owin --version 1.0.0
<PackageReference Include="LeakyBucket.Owin" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LeakyBucket.Owin --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LeakyBucket.Owin, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install LeakyBucket.Owin as a Cake Addin
#addin nuget:?package=LeakyBucket.Owin&version=1.0.0

// Install LeakyBucket.Owin as a Cake Tool
#tool nuget:?package=LeakyBucket.Owin&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

LeakyBucket.Owin

Owin middleware that implements the leaky bucket algorithm for request throttling.

Build status
Coverage Status
NuGet

This package is available via install the NuGet:

Install-Package LeakyBucket.Owin

Then, you can enable LeakyBucket rate limiting by adding the LeakyBucketMiddleware to the Owin app:

using System;
using LeakyBucket.Owin;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(MyWebApp.Startup))]

namespace MyWebApp
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseLeakyBucket(new LeakyBucketConfiguration
            {
              MaxNumberOfRequests = 100,
              RefreshRate = TimeSpan.FromSeconds(1)
            });
        }
    }
}

How it works

  1. When a request comes in it will extract the IClientIdentifier from the IOwinContext 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 LeakyBucketConfiguration 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 LeakyBucketConfiguration can specifies a function that determines what a client is. By default it creates a DefaultClientIdentifier that holds a reference to the remote address.

LeakyBucket.Owin

Owin middleware that implements the leaky bucket algorithm for request throttling.

Build status
Coverage Status
NuGet

This package is available via install the NuGet:

Install-Package LeakyBucket.Owin

Then, you can enable LeakyBucket rate limiting by adding the LeakyBucketMiddleware to the Owin app:

using System;
using LeakyBucket.Owin;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(MyWebApp.Startup))]

namespace MyWebApp
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseLeakyBucket(new LeakyBucketConfiguration
            {
              MaxNumberOfRequests = 100,
              RefreshRate = TimeSpan.FromSeconds(1)
            });
        }
    }
}

How it works

  1. When a request comes in it will extract the IClientIdentifier from the IOwinContext 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 LeakyBucketConfiguration 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 LeakyBucketConfiguration can specifies a function that determines what a client is. By default it creates a DefaultClientIdentifier that holds a reference to the remote address.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 640 2/18/2018
1.0.0 576 1/14/2018