durin.throttling
)ï
Durin provides a throttling class which make use of the durin.models.Client
model it offers.
Usage is the same way as other DRF throttling classes.
Example settings.py
:
#...snip... REST_FRAMEWORK = { "DEFAULT_THROTTLE_CLASSES": ["durin.throttling.UserClientRateThrottle"], "DEFAULT_THROTTLE_RATES": {"user_per_client": "10/min"}, } #...snip...
"user_per_client"
default scope
for the UserClientRateThrottle
class.
The rate defined here serves as the default rate incase the throttle_rate
field on durin.models.Client
is null
.
durin.throttling.
UserClientRateThrottle
[source]ï
Bases: rest_framework.throttling.UserRateThrottle
Throttles requests by identifying the authed user-client pair.
This is useful if you want to define different user throttle rates per durin.models.Client
instance.
New in version 0.2.
allow_request
(request, view)[source]ï
The rate
is set here because we need access to request
object which is not available inside get_rate()
.
cache_format
= 'throttle_%(scope)s_%(ident)s'ï
Same as the default
get_cache_key
(request, view) → str[source]ï
Should return a unique cache-key which can be used for throttling. Must be overridden.
May return None if the request should not be throttled.
scope
= 'user_per_client'ï
Scope for this throttle
validate_client_throttle_rate
(rate)[source]ï
Used for validating the throttle_rate
field on durin.models.Client
.
For internal use only.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4