Skip to content

Commit

Permalink
fix(guard): Change RateLimit header prefix to X-RateLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen authored and jmcdo29 committed May 31, 2020
1 parent 25e33c8 commit 328c0a3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/throttler.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ThrottlerGuard implements CanActivate {
// TODO: Return true if current route is in ignoreRoutes.
async canActivate(context: ExecutionContext): Promise<boolean> {
const handler = context.getHandler();
const headerPrefix = 'X-RateLimit';

const limit = this.reflector.get<number>(THROTTLER_LIMIT, handler);
const ttl = this.reflector.get<number>(THROTTLER_TTL, handler);
Expand All @@ -37,9 +38,9 @@ export class ThrottlerGuard implements CanActivate {
throw new ThrottlerException();
}

res.header('RateLimit-Limit', limit);
res.header('RateLimit-Remaining', Math.max(0, limit - record.length));
res.header('RateLimit-Reset', nearestExpiryTime);
res.header(`${headerPrefix}-Limit`, limit);
res.header(`${headerPrefix}-Remaining`, Math.max(0, limit - record.length));
res.header(`${headerPrefix}-Reset`, nearestExpiryTime);

this.storageService.addRecord(key, ttl);
return true;
Expand Down

0 comments on commit 328c0a3

Please sign in to comment.