LeakyBucket.Owin 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package LeakyBucket.Owin --version 1.0.0
NuGet\Install-Package LeakyBucket.Owin -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: LeakyBucket.Owin, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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

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.

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 1,108 2/18/2018
1.0.0 1,025 1/14/2018