class ThrottlerGuard implements CanActivate {
protected headerPrefix: 'X-RateLimit'
protected errorMessage: throttlerMessage
protected options: ThrottlerModuleOptions
protected storageService: ThrottlerStorage
protected reflector: Reflector
canActivate(context: ExecutionContext): Promise<boolean>
protected handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean>
protected getTracker(req: Record<string, any>): string
protected getRequestResponse(context: ExecutionContext): {...}
protected generateKey(context: ExecutionContext, suffix: string): string
protected throwThrottlingException(context: ExecutionContext): void
}
Methods
canActivate()
|
|
Throttle requests against their TTL limit and whether to allow or deny it.
Based on the context type different handlers will be called.
|
canActivate(context: ExecutionContext): Promise<boolean>
Parameters
Returns
Promise<boolean>
Throws
ThrottlerException
|
handleRequest()
|
|
Throttles incoming HTTP requests.
All the outgoing requests will contain RFC-compatible RateLimit headers.
|
protected handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean>
Parameters
Returns
Promise<boolean>
Throws
ThrottlerException
|
getTracker()
|
protected getTracker(req: Record<string, any>): string
Parameters
| Option |
Type |
Description |
req
|
Record |
|
Returns
string
|
getRequestResponse()
|
protected getRequestResponse(context: ExecutionContext): {
req: Record<string, any>;
res: Record<string, any>;
}
Parameters
Returns
{
req: Record<string, any>;
res: Record<string, any>;
}
|
generateKey()
|
|
Generate a hashed key that will be used as a storage key.
The key will always be a combination of the current context and IP.
|
protected generateKey(context: ExecutionContext, suffix: string): string
Parameters
Returns
string
|
throwThrottlingException()
|
|
Throws an exception for the event that the rate limit has been exceeded.
|
protected throwThrottlingException(context: ExecutionContext): void
Parameters
Returns
void
Throws
ThrottlerException
|
|
The context parameter allows to access the context when overwriting
the method.
|