Comments (7)
Yes setting the defaults to 0 should work, the default values supplied in the constructor applies to actions that don't have the EnableThrottling attribute, or when you've missed to supply a PerFoo rate in the attribute.
So if the default policy has a perDay limit, and the EnableThrottling doesn't have it, then the perDay limit from ThrottlePolicy constructor will be used.
If all your action have EnableThrottling with every PerX specified then none of the constructor values will apply.
from mvcthrottle.
Okay that makes good sense.
But what happens, for example, if I want to throttle an action by day. In the attribute, is it enough to specify [EnableThrottling(PerDay = 123)]
, or must I also specify for PerSecond =
and PerHour =
as well - to override the 0
value in the defaults?
from mvcthrottle.
No need to specify those. You need to put the rate types you want to enable in the constructor and use them in attribute. The 0 value should disable the rate limit type, please make a test and let me know.
from mvcthrottle.
"You need to put the rate types you want to enable in the constructor"... I assume you mean the ctor of the global filter. It's for a big project, so we "enabled" all of them to 0
.
Okay I tested and it seems to work, but we have many places where it's used, and I'm trying to go through many combinations to see what happens.
from mvcthrottle.
It's a pity this isn't on the main docs, so for anybody else who wants to know, here is my understanding:
- The global filter takes rate limits. These are the defaults.
- The defaults are used if you don't specify custom rate limits in the
[EnableThrottling]
attribute. - There are various ways to do throttling. If you prefer to specify custom limits on your attributes, and never rely on defaults, then you must set
0
as the default for all rate limits. So you do this:Policy = new ThrottlePolicy(perSecond:0, perMinute:0, perHour:0, perDay:0, perWeek:0) { ...
. Then specify a rate limit in the attribute, for example:[EnableThrottling(PerHour = 10)]
. If you take this approach, then the custom rate limits will override the defaults. But also, if your attribute is for e.g.[EnableThrottling(PerHour = 10)]
then it not only overrides theperHour:
default, but also ignores theperSecond:
andperMinute:
defaults. This means you don't need to specify custom values for all limits, only the one you are interested in. You don't need to do this:[EnableThrottling(PerSecond = x, PerMinute = y, PerHour = 10)]
.
Please correct anything if it's wrong? I'll update more when I have tested more.
from mvcthrottle.
You are right, this is the intended behavior. I must find a better way to enable/disable limit types.
If you don't specify a rate limit type when you register the filter, even if you specified that type in the attribute it will get ignored.
ThrottlePolicy(perSecond:0, perMinute:0)
[EnableThrottling(PerHour = 10)]
In the example above, PerHour will get ignored.
Thanks for running these tests.
from mvcthrottle.
Oops, so I misunderstood... 😄
In your example I thought the PerHour
will be used, but you say it will be ignored (because it has no corresponding default in the filter). So that means that there will be "maximum" throttling for that attribute, because PerHour
is ignored, and everything else is 0
?
Sorry, I am maybe a bit "slow" (I've been throttled)...
I agree we should think what is a good way to handle this use case. Or keep it as it is, but make a "formal" documentation for it...
from mvcthrottle.
Related Issues (18)
- Issue 429 instead of 409.
- Adding honeyPot and reCaptcha as attributes
- Get correct client IP address from X-Forwarded-For list HOT 3
- Rename DisableThrottingAttribute HOT 2
- DisableThrottling on Class HOT 1
- IsWhitelisted chokes if the UserAgent is null HOT 1
- Null user agent exceptions HOT 1
- What's the difference between EndpointWhitelist and [DisableThrottling]?
- Use with ServiceStack? HOT 1
- System.FormatException thrown by poorly formatted HTTP_X_FORWARDED_FOR
- How to use it to API HOT 1
- How to configure dynamically?
- IndexOutOfRangeException when using slash to define IP range
- Identity ClientIP Including Port
- IP usage flawed for some scenarios
- Requests always stacking HOT 3
- globally enable throttling HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mvcthrottle.