LeakyBucket.Owin
1.0.0
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
<PackageReference Include="LeakyBucket.Owin" Version="1.0.0" />
paket add LeakyBucket.Owin --version 1.0.0
#r "nuget: LeakyBucket.Owin, 1.0.0"
// 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.
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
- When a request comes in it will extract the
IClientIdentifier
from theIOwinContext
with the function specified in the configuration. - It will check for any requests that have passed the specified
RefreshRate
and remove them from theIRequestStore
. - It will then add the new request to the
IRequestStore
. - It will check how many requests are remaining.
- 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 | Versions 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. |
-
- Microsoft.Owin (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.