KnowYourLimits.AspNetCore
2.3.2
See the version list below for details.
dotnet add package KnowYourLimits.AspNetCore --version 2.3.2
NuGet\Install-Package KnowYourLimits.AspNetCore -Version 2.3.2
<PackageReference Include="KnowYourLimits.AspNetCore" Version="2.3.2" />
paket add KnowYourLimits.AspNetCore --version 2.3.2
#r "nuget: KnowYourLimits.AspNetCore, 2.3.2"
// Install KnowYourLimits.AspNetCore as a Cake Addin #addin nuget:?package=KnowYourLimits.AspNetCore&version=2.3.2 // Install KnowYourLimits.AspNetCore as a Cake Tool #tool nuget:?package=KnowYourLimits.AspNetCore&version=2.3.2
KnowYourLimits
A rate limiting library for .Net projects.
Currently provides middleware for:
- AspNet Core
Available rate limiting strategies:
- Leaky Bucket
When a client exceeds their request limit, a 429 Too Many Requests
status will be returned.
Setup
The middleware should be attached to the application as high in the order as possible, to intercept requests early.
For example, to configure the rate limiter to allow 4 requests per second, with a maximum of 100 requests, see below:
var rateLimitingConfiguration = new LeakyBucketConfiguration
{
MaxRequests = 100,
LeakRate = TimeSpan.FromSeconds(1),
LeakAmount = 4,
IdentityProvider = new CustomIdentityProvider(), // If not set, defaults to using the remote address
EnableHeaders = true, // If true, a set of headers, documented below, will be returned on all responses describing the rate limits
HeaderPrefix = "X-MYORG-" // This will be appended to all generated headers.
};
app.UseRateLimiting(new LeakyBucketRateLimitStrategy(rateLimitingConfiguration));
By default client requests will be identified using the remote address of the request. To implement a custom identity provider, implement the IClientIdentityProvider
interface and pass it in to the configuration.
Headers
If EnableHeaders
is true
headers will be added to all responses. These are dependant on the limiting strategy used.
For Leaky Bucket, the headers are:
RateLimit-Remaining - The remaining allowance
RateLimit-LeakRate - The rate at which tokens leak out of the bucket
RateLimit-LeakAmount - The number of tokens to leak at each interval
RateLimit-Cost - The number of tokens a single request costs
Using the HeaderPrefix
setting, you can customize the prefix for these headers. The default prefix is X-
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- KnowYourLimits (>= 2.1.0)
- Microsoft.AspNetCore (>= 2.0.1)
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 |
---|---|---|
5.1.0 | 3,032 | 5/5/2020 |
5.0.0 | 1,001 | 5/4/2020 |
4.1.0 | 1,241 | 1/24/2020 |
4.0.1 | 1,186 | 11/13/2019 |
3.0.0 | 1,052 | 11/11/2019 |
2.3.2 | 2,224 | 7/24/2018 |
2.3.1 | 1,350 | 7/24/2018 |
2.3.0 | 1,351 | 7/24/2018 |
2.2.0 | 1,702 | 4/27/2018 |
2.2.0-alpha | 1,467 | 4/27/2018 |
2.1.1-alpha | 1,394 | 4/27/2018 |
2.1.0-alpha | 1,320 | 4/27/2018 |
2.0.0 | 1,823 | 1/16/2018 |
1.0.2 | 1,636 | 1/16/2018 |
1.0.1 | 1,584 | 1/16/2018 |
1.0.0 | 1,620 | 1/15/2018 |