carbond.limiter.LimiterPolicy

LimiterPolicy is used to define some policy over requests to a particular endpoint based on some key representing a request (e.g., as extracted by an accompanying instance of LimiterSelector) and some historical context.

Class

class carbond.limiter.LimiterPolicy()

abstract

sharedState
Boolean
Required
Default false
Description If true, state will be shared with any other PolicyLimiter that also indicates it wants to share state.
limiter
Required
Description The Limiter instance using this policy.
node
Required
Description The Endpoint this the limiter instance is attached to.
stateKey
String
Description This is a read-only attribute used to lookup the state object for a LimiterPolicy instance.
state
Description This is a read-only attribute that holding a pointer to the state object associated with this policy.
initializeState  
Arguments
  • state – a shared LimiterPolicyState instance or undefined
Description Called on initialization. Sets and/or gets the policy state.
allow  
Arguments
  • req (express.request) – the current Request object
  • res (express.response) – the current Response object
  • selector (String) – A string used to group similar requests
Returns true if the policy allows the request, else false
Return type Boolean
Description abstract
Description This method should be overridden to evaluate the current request as identified by selector in the context of state and decide whether or not it should be allowed.

Example