@nestjs/throttler 6.4.0 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -63
- package/dist/throttler-module-options.interface.d.ts +3 -1
- package/dist/throttler.guard.d.ts +1 -1
- package/dist/throttler.guard.js +11 -5
- package/dist/throttler.guard.js.map +1 -1
- package/dist/throttler.service.d.ts +1 -1
- package/dist/throttler.service.js +10 -10
- package/dist/throttler.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +43 -41
package/README.md
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
|
|
19
19
|
A Rate-Limiter for NestJS, regardless of the context.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Throttler ensures that users can only make `limit` requests per `ttl` to each endpoint. By default, users are identified by their IP address. This behavior can be customized by providing your own `getTracker` function. See [Proxies](#proxies) for an example where this is useful.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Throttler comes with a built-in in-memory cache to keep track of the requests. It supports alternate storage providers. For an overview, see [Community Storage Providers](#community-storage-providers).
|
|
24
24
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
@@ -32,23 +32,7 @@ $ npm i --save @nestjs/throttler
|
|
|
32
32
|
|
|
33
33
|
`@nestjs/throttler@^1` is compatible with Nest v7 while `@nestjs/throttler@^2` is compatible with Nest v7 and Nest v8, but it is suggested to be used with only v8 in case of breaking changes against v7 that are unseen.
|
|
34
34
|
|
|
35
|
-
For NestJS v10, please use version 4.1.0 or above
|
|
36
|
-
|
|
37
|
-
<div id="toc"></div>
|
|
38
|
-
|
|
39
|
-
## Table of Contents
|
|
40
|
-
|
|
41
|
-
- [Description](#description)
|
|
42
|
-
- [Versions](#versions)
|
|
43
|
-
- [Table of Contents](#table-of-contents)
|
|
44
|
-
- [Usage](#usage)
|
|
45
|
-
- [ThrottlerModule](#throttlermodule)
|
|
46
|
-
- [Customization](#customization)
|
|
47
|
-
- [ThrottlerStorage](#storages)
|
|
48
|
-
- [Proxies](#proxies)
|
|
49
|
-
- [Working with Websockets](#websockets)
|
|
50
|
-
- [Working with GraphQL](#graphql)
|
|
51
|
-
- [Community Storage Providers](#community-storage-providers)
|
|
35
|
+
For NestJS v10, please use version 4.1.0 or above.
|
|
52
36
|
|
|
53
37
|
## Usage
|
|
54
38
|
|
|
@@ -110,21 +94,68 @@ There may come upon times where you want to set up multiple throttling definitio
|
|
|
110
94
|
export class AppModule {}
|
|
111
95
|
```
|
|
112
96
|
|
|
113
|
-
####
|
|
97
|
+
#### Important note on using decorators with Named Throttlers:
|
|
114
98
|
|
|
115
|
-
|
|
99
|
+
When you have configured named throttlers (e.g., 'short', 'medium', 'long' as shown above), both the `@SkipThrottle()` and `@Throttle()` decorators must be provided with an object where keys are the names of your throttlers.
|
|
116
100
|
|
|
101
|
+
If you use `@SkipThrottle()` without specifying the names, it will not skip any of your named throttlers. Similarly, `@Throttle()` without specifying names cannot override settings for specific named throttlers.
|
|
102
|
+
|
|
103
|
+
**Correct usage with named throttlers:**
|
|
104
|
+
|
|
105
|
+
To skip specific named throttlers:
|
|
117
106
|
```typescript
|
|
118
|
-
@SkipThrottle()
|
|
107
|
+
@SkipThrottle({ short: true, medium: true })
|
|
108
|
+
@Controller('users')
|
|
109
|
+
export class UsersController {}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
To override limits for specific named throttlers:
|
|
113
|
+
```typescript
|
|
114
|
+
@Throttle({ short: { limit: 5, ttl: 1000 }, medium: { limit: 30, ttl: 10000 } })
|
|
115
|
+
@Get()
|
|
116
|
+
findAll() {
|
|
117
|
+
return "Custom limits for specific throttlers";
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Incorrect usage** (will not work as intended for named throttlers):
|
|
122
|
+
```typescript
|
|
123
|
+
@SkipThrottle() // This will NOT skip any named throttlers
|
|
119
124
|
@Controller('users')
|
|
120
125
|
export class UsersController {}
|
|
121
126
|
```
|
|
122
127
|
|
|
123
|
-
|
|
128
|
+
For more details on this behavior, especially if migrating from older versions, please refer to the [Migration to v5](#migrating-to-v5-from-earlier-versions) guide.
|
|
129
|
+
|
|
130
|
+
### Customization
|
|
131
|
+
|
|
132
|
+
There may be a time where you want to bind the guard to a controller or globally, but want to disable rate limiting for one or more of your endpoints. For that, you can use the `@SkipThrottle()` decorator to negate the throttler for an entire class or a single route.
|
|
133
|
+
|
|
134
|
+
The `@SkipThrottle()` decorator behaves differently based on your ThrottlerModule configuration:
|
|
135
|
+
|
|
136
|
+
1. **For a single, default (unnamed) throttler:** You can use `@SkipThrottle()`, `@SkipThrottle(true)`, or `@SkipThrottle({ default: true })`.
|
|
124
137
|
|
|
125
138
|
```typescript
|
|
126
139
|
@SkipThrottle()
|
|
127
140
|
@Controller('users')
|
|
141
|
+
export class UsersController {}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
2. **For multiple named throttlers** (e.g., 'short', 'medium'): You must provide an object where keys are the names of the throttlers you wish to skip, and values are `true`.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
@SkipThrottle({ short: true, medium: true })
|
|
148
|
+
@Controller('users')
|
|
149
|
+
export class UsersController {}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
> **Important:** Simply using `@SkipThrottle()` without an object will not skip any named throttlers. See the [Multiple Throttler Definitions](#multiple-throttler-definitions) section for a detailed example and explanation.
|
|
153
|
+
|
|
154
|
+
The `@SkipThrottle()` decorator can also be used to negate the skipping of a route in a class that is already skipped:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
@SkipThrottle({ default: true })
|
|
158
|
+
@Controller('users')
|
|
128
159
|
export class UsersController {
|
|
129
160
|
// Rate limiting is applied to this route.
|
|
130
161
|
@SkipThrottle({ default: false })
|
|
@@ -149,9 +180,11 @@ findAll() {
|
|
|
149
180
|
}
|
|
150
181
|
```
|
|
151
182
|
|
|
152
|
-
|
|
183
|
+
### Proxies
|
|
184
|
+
|
|
185
|
+
If your application runs behind a proxy server, check the specific HTTP adapter options ([express](http://expressjs.com/en/guide/behind-proxies.html) and [fastify](https://www.fastify.io/docs/latest/Reference/Server/#trustproxy)) for the `trust proxy` option and enable it. Doing so will allow you to get the original IP address from the `X-Forwarded-For` header.
|
|
153
186
|
|
|
154
|
-
|
|
187
|
+
For express, no further configuration is needed because express sets `req.ip` to the client IP if `trust proxy` is enabled. For fastify, you need to read the client IP from `req.ips` instead. The following example is only needed for fastify, but works with both engines:
|
|
155
188
|
|
|
156
189
|
```typescript
|
|
157
190
|
// throttler-behind-proxy.guard.ts
|
|
@@ -161,10 +194,10 @@ import { Injectable } from '@nestjs/common';
|
|
|
161
194
|
@Injectable()
|
|
162
195
|
export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
|
|
163
196
|
protected getTracker(req: Record<string, any>): Promise<string> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
197
|
+
// The client IP is the leftmost IP in req.ips. You can individualize IP
|
|
198
|
+
// extraction to meet your own needs.
|
|
199
|
+
const tracker = req.ips.length > 0 ? req.ips[0] : req.ip;
|
|
200
|
+
return Promise.resolve(tracker);
|
|
168
201
|
}
|
|
169
202
|
}
|
|
170
203
|
|
|
@@ -174,9 +207,9 @@ import { ThrottlerBehindProxyGuard } from './throttler-behind-proxy.guard';
|
|
|
174
207
|
@UseGuards(ThrottlerBehindProxyGuard)
|
|
175
208
|
```
|
|
176
209
|
|
|
177
|
-
>
|
|
210
|
+
> **Hint:** You can find the API of the `req` Request object for express [here](https://expressjs.com/en/api.html#req.ips) and for fastify [here](https://www.fastify.io/docs/latest/Reference/Request/).
|
|
178
211
|
|
|
179
|
-
|
|
212
|
+
### Websockets
|
|
180
213
|
|
|
181
214
|
This module can work with websockets, but it requires some class extension. You can extend the `ThrottlerGuard` and override the `handleRequest` method like so:
|
|
182
215
|
|
|
@@ -184,7 +217,7 @@ This module can work with websockets, but it requires some class extension. You
|
|
|
184
217
|
@Injectable()
|
|
185
218
|
export class WsThrottlerGuard extends ThrottlerGuard {
|
|
186
219
|
async handleRequest(requestProps: ThrottlerRequest): Promise<boolean> {
|
|
187
|
-
const { context, limit, ttl, throttler, blockDuration,
|
|
220
|
+
const { context, limit, ttl, throttler, blockDuration, generateKey } = requestProps;
|
|
188
221
|
|
|
189
222
|
const client = context.switchToWs().getClient();
|
|
190
223
|
const tracker = client._socket.remoteAddress;
|
|
@@ -192,8 +225,6 @@ export class WsThrottlerGuard extends ThrottlerGuard {
|
|
|
192
225
|
const { totalHits, timeToExpire, isBlocked, timeToBlockExpire } =
|
|
193
226
|
await this.storageService.increment(key, ttl, limit, blockDuration, throttler.name);
|
|
194
227
|
|
|
195
|
-
const getThrottlerSuffix = (name: string) => (name === 'default' ? '' : `-${name}`);
|
|
196
|
-
|
|
197
228
|
// Throw an error when the user reached their limit.
|
|
198
229
|
if (isBlocked) {
|
|
199
230
|
await this.throwThrottlingException(context, {
|
|
@@ -213,18 +244,18 @@ export class WsThrottlerGuard extends ThrottlerGuard {
|
|
|
213
244
|
}
|
|
214
245
|
```
|
|
215
246
|
|
|
216
|
-
>
|
|
247
|
+
> **Hint:** If you are using ws, it is necessary to replace the `_socket` with `conn`.
|
|
217
248
|
|
|
218
249
|
There's a few things to keep in mind when working with WebSockets:
|
|
219
250
|
|
|
220
251
|
- Guard cannot be registered with the `APP_GUARD` or `app.useGlobalGuards()`
|
|
221
252
|
- When a limit is reached, Nest will emit an `exception` event, so make sure there is a listener ready for this
|
|
222
253
|
|
|
223
|
-
>
|
|
254
|
+
> **Hint:** If you are using the `@nestjs/platform-ws` package you can use `client._socket.remoteAddress` instead.
|
|
224
255
|
|
|
225
|
-
|
|
256
|
+
### GraphQL
|
|
226
257
|
|
|
227
|
-
The `ThrottlerGuard` can also be used to work with GraphQL requests. Again, the guard can be extended, but this time the `getRequestResponse` method will be overridden
|
|
258
|
+
The `ThrottlerGuard` can also be used to work with GraphQL requests. Again, the guard can be extended, but this time the `getRequestResponse` method will be overridden:
|
|
228
259
|
|
|
229
260
|
```typescript
|
|
230
261
|
@Injectable()
|
|
@@ -261,7 +292,7 @@ GraphQLModule.forRoot({
|
|
|
261
292
|
});
|
|
262
293
|
```
|
|
263
294
|
|
|
264
|
-
|
|
295
|
+
### Configuration
|
|
265
296
|
|
|
266
297
|
The following options are valid for the object passed to the array of the `ThrottlerModule`'s options:
|
|
267
298
|
|
|
@@ -280,7 +311,7 @@ The following options are valid for the object passed to the array of the `Throt
|
|
|
280
311
|
</tr>
|
|
281
312
|
<tr>
|
|
282
313
|
<td><code>blockDuration</code></td>
|
|
283
|
-
<td>the number of milliseconds
|
|
314
|
+
<td>the number of milliseconds the request will be blocked</td>
|
|
284
315
|
</tr>
|
|
285
316
|
<tr>
|
|
286
317
|
<td><code>ignoreUserAgents</code></td>
|
|
@@ -292,11 +323,11 @@ The following options are valid for the object passed to the array of the `Throt
|
|
|
292
323
|
</tr>
|
|
293
324
|
<tr>
|
|
294
325
|
<td><code>getTracker</code></td>
|
|
295
|
-
<td>a function that takes in the <code>Request</code> and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
|
|
326
|
+
<td>a function that takes in the <code>Request</code> and <code>ExecutionContext</code>, and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
|
|
296
327
|
</tr>
|
|
297
328
|
<tr>
|
|
298
329
|
<td><code>generateKey</code></td>
|
|
299
|
-
<td>a function that takes in the <code>ExecutionContext</code>, the
|
|
330
|
+
<td>a function that takes in the <code>ExecutionContext</code>, the tracker <code>string</code> and the throttler name as a <code>string</code> and returns a <code>string</code> to override the final key which will be used to store the rate limit value. This overrides the default logic of the <code>generateKey</code> method</td>
|
|
300
331
|
</tr>
|
|
301
332
|
</table>
|
|
302
333
|
|
|
@@ -305,7 +336,7 @@ If you need to set up storages instead, or want to use a some of the above optio
|
|
|
305
336
|
<table>
|
|
306
337
|
<tr>
|
|
307
338
|
<td><code>storage</code></td>
|
|
308
|
-
<td>a custom storage service for where the throttling should be kept track. <a href="
|
|
339
|
+
<td>a custom storage service for where the throttling should be kept track. <a href="#storages">See Storages below.</a></td>
|
|
309
340
|
</tr>
|
|
310
341
|
<tr>
|
|
311
342
|
<td><code>ignoreUserAgents</code></td>
|
|
@@ -325,11 +356,11 @@ If you need to set up storages instead, or want to use a some of the above optio
|
|
|
325
356
|
</tr>
|
|
326
357
|
<tr>
|
|
327
358
|
<td><code>getTracker</code></td>
|
|
328
|
-
<td>a function that takes in the <code>Request</code> and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
|
|
359
|
+
<td>a function that takes in the <code>Request</code> and <code>ExecutionContext</code>, and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
|
|
329
360
|
</tr>
|
|
330
361
|
<tr>
|
|
331
362
|
<td><code>generateKey</code></td>
|
|
332
|
-
<td>a function that takes in the <code>ExecutionContext</code>, the
|
|
363
|
+
<td>a function that takes in the <code>ExecutionContext</code>, the tracker <code>string</code> and the throttler name as a <code>string</code> and returns a <code>string</code> to override the final key which will be used to store the rate limit value. This overrides the default logic of the <code>generateKey</code> method</td>
|
|
333
364
|
</tr>
|
|
334
365
|
</table>
|
|
335
366
|
|
|
@@ -373,40 +404,50 @@ export class AppModule {}
|
|
|
373
404
|
|
|
374
405
|
This is doable, as long as `ThrottlerConfigService` implements the interface `ThrottlerOptionsFactory`.
|
|
375
406
|
|
|
376
|
-
|
|
407
|
+
### Storages
|
|
377
408
|
|
|
378
409
|
The built in storage is an in memory cache that keeps track of the requests made until they have passed the TTL set by the global options. You can drop in your own storage option to the `storage` option of the `ThrottlerModule` so long as the class implements the `ThrottlerStorage` interface.
|
|
379
410
|
|
|
380
|
-
>
|
|
411
|
+
> **Note:** `ThrottlerStorage` can be imported from `@nestjs/throttler`.
|
|
381
412
|
|
|
382
|
-
|
|
413
|
+
### Time Helpers
|
|
383
414
|
|
|
384
415
|
There are a couple of helper methods to make the timings more readable if you prefer to use them over the direct definition. `@nestjs/throttler` exports five different helpers, `seconds`, `minutes`, `hours`, `days`, and `weeks`. To use them, simply call `seconds(5)` or any of the other helpers, and the correct number of milliseconds will be returned.
|
|
385
416
|
|
|
386
|
-
|
|
417
|
+
### Migrating to v5 from earlier versions
|
|
418
|
+
|
|
419
|
+
If you migrate to v5 from earlier versions, you need to wrap your options in an array.
|
|
420
|
+
|
|
421
|
+
If you are using a custom storage, you should wrap you `ttl` and `limit` in an array and assign it to the `throttlers` property of the options object.
|
|
387
422
|
|
|
388
|
-
|
|
423
|
+
Any `@SkipThrottle()` should now take in an object with `string: boolean` props. The strings are the names of the throttlers. If you do not have a name, pass the string `'default'`, as this is what will be used under the hood otherwise.
|
|
389
424
|
|
|
390
|
-
|
|
391
|
-
array and assign it to the `throttlers` property of the options object.
|
|
425
|
+
**Migration examples for decorators:**
|
|
392
426
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
427
|
+
```typescript
|
|
428
|
+
// Before v5
|
|
429
|
+
@SkipThrottle()
|
|
430
|
+
@Throttle(10, 60)
|
|
431
|
+
|
|
432
|
+
// After v5 (with default throttler)
|
|
433
|
+
@SkipThrottle({ default: true })
|
|
434
|
+
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
|
435
|
+
|
|
436
|
+
// After v5 (with named throttlers)
|
|
437
|
+
@SkipThrottle({ short: true, medium: true })
|
|
438
|
+
@Throttle({ short: { limit: 5, ttl: 1000 }, long: { limit: 100, ttl: 60000 } })
|
|
439
|
+
```
|
|
396
440
|
|
|
397
|
-
Any `@Throttle()` decorators should also now take in an object with string keys,
|
|
398
|
-
relating to the names of the throttler contexts (again, `'default'` if no name)
|
|
399
|
-
and values of objects that have `limit` and `ttl` keys.
|
|
441
|
+
Any `@Throttle()` decorators should also now take in an object with string keys, relating to the names of the throttler contexts (again, `'default'` if no name) and values of objects that have `limit` and `ttl` keys.
|
|
400
442
|
|
|
401
|
-
>
|
|
402
|
-
> in seconds for readability, use the `seconds` helper from this package. It just
|
|
403
|
-
> multiplies the ttl by 1000 to make it in milliseconds.
|
|
443
|
+
> **Important:** The `ttl` is now in **milliseconds**. If you want to keep your ttl in seconds for readability, use the `seconds` helper from this package. It just multiplies the ttl by 1000 to make it in milliseconds.
|
|
404
444
|
|
|
405
|
-
|
|
445
|
+
> **Note:** When using named throttlers, simply using `@SkipThrottle()` without parameters will not work as expected. See the [Important note on using decorators with Named Throttlers](#important-note-on-using-decorators-with-named-throttlers) section for details.
|
|
406
446
|
|
|
407
447
|
## Community Storage Providers
|
|
408
448
|
|
|
409
|
-
- [Redis](https://github.com/
|
|
449
|
+
- [Redis](https://github.com/CSenshi/nestjs-redis/tree/main/packages/throttler-storage) (`node-redis` based)
|
|
450
|
+
- [Redis](https://github.com/jmcdo29/nest-lab/tree/main/packages/throttler-storage-redis) (`ioredis` based)
|
|
410
451
|
- [Mongo](https://www.npmjs.com/package/nestjs-throttler-storage-mongo)
|
|
411
452
|
|
|
412
453
|
Feel free to submit a PR with your custom storage provider being added to this list.
|
|
@@ -11,15 +11,17 @@ export interface ThrottlerOptions {
|
|
|
11
11
|
skipIf?: (context: ExecutionContext) => boolean;
|
|
12
12
|
getTracker?: ThrottlerGetTrackerFunction;
|
|
13
13
|
generateKey?: ThrottlerGenerateKeyFunction;
|
|
14
|
+
setHeaders?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export type ThrottlerModuleOptions = Array<ThrottlerOptions> | {
|
|
16
|
-
skipIf?: (context: ExecutionContext) => boolean;
|
|
17
17
|
ignoreUserAgents?: RegExp[];
|
|
18
|
+
skipIf?: (context: ExecutionContext) => boolean;
|
|
18
19
|
getTracker?: ThrottlerGetTrackerFunction;
|
|
19
20
|
generateKey?: ThrottlerGenerateKeyFunction;
|
|
20
21
|
errorMessage?: string | ((context: ExecutionContext, throttlerLimitDetail: ThrottlerLimitDetail) => string);
|
|
21
22
|
storage?: ThrottlerStorage;
|
|
22
23
|
throttlers: Array<ThrottlerOptions>;
|
|
24
|
+
setHeaders?: boolean;
|
|
23
25
|
};
|
|
24
26
|
export interface ThrottlerOptionsFactory {
|
|
25
27
|
createThrottlerOptions(): Promise<ThrottlerModuleOptions> | ThrottlerModuleOptions;
|
|
@@ -10,7 +10,7 @@ export declare class ThrottlerGuard implements CanActivate {
|
|
|
10
10
|
protected headerPrefix: string;
|
|
11
11
|
protected errorMessage: string;
|
|
12
12
|
protected throttlers: Array<ThrottlerOptions>;
|
|
13
|
-
protected commonOptions: Pick<ThrottlerOptions, 'skipIf' | 'ignoreUserAgents' | 'getTracker' | 'generateKey'>;
|
|
13
|
+
protected commonOptions: Pick<ThrottlerOptions, 'skipIf' | 'ignoreUserAgents' | 'getTracker' | 'generateKey' | 'setHeaders'>;
|
|
14
14
|
constructor(options: ThrottlerModuleOptions, storageService: ThrottlerStorage, reflector: Reflector);
|
|
15
15
|
onModuleInit(): Promise<void>;
|
|
16
16
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
package/dist/throttler.guard.js
CHANGED
|
@@ -51,6 +51,7 @@ let ThrottlerGuard = class ThrottlerGuard {
|
|
|
51
51
|
ignoreUserAgents: this.options.ignoreUserAgents,
|
|
52
52
|
getTracker: this.options.getTracker,
|
|
53
53
|
generateKey: this.options.generateKey,
|
|
54
|
+
setHeaders: this.options.setHeaders,
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
(_a = (_c = this.commonOptions).getTracker) !== null && _a !== void 0 ? _a : (_c.getTracker = this.getTracker.bind(this));
|
|
@@ -99,7 +100,7 @@ let ThrottlerGuard = class ThrottlerGuard {
|
|
|
99
100
|
return false;
|
|
100
101
|
}
|
|
101
102
|
async handleRequest(requestProps) {
|
|
102
|
-
var _a;
|
|
103
|
+
var _a, _b, _c;
|
|
103
104
|
const { context, limit, ttl, throttler, blockDuration, getTracker, generateKey } = requestProps;
|
|
104
105
|
const { req, res } = this.getRequestResponse(context);
|
|
105
106
|
const ignoreUserAgents = (_a = throttler.ignoreUserAgents) !== null && _a !== void 0 ? _a : this.commonOptions.ignoreUserAgents;
|
|
@@ -114,8 +115,11 @@ let ThrottlerGuard = class ThrottlerGuard {
|
|
|
114
115
|
const key = generateKey(context, tracker, throttler.name);
|
|
115
116
|
const { totalHits, timeToExpire, isBlocked, timeToBlockExpire } = await this.storageService.increment(key, ttl, limit, blockDuration, throttler.name);
|
|
116
117
|
const getThrottlerSuffix = (name) => (name === 'default' ? '' : `-${name}`);
|
|
118
|
+
const setHeaders = (_c = (_b = throttler.setHeaders) !== null && _b !== void 0 ? _b : this.commonOptions.setHeaders) !== null && _c !== void 0 ? _c : true;
|
|
117
119
|
if (isBlocked) {
|
|
118
|
-
|
|
120
|
+
if (setHeaders) {
|
|
121
|
+
res.header(`Retry-After${getThrottlerSuffix(throttler.name)}`, timeToBlockExpire);
|
|
122
|
+
}
|
|
119
123
|
await this.throwThrottlingException(context, {
|
|
120
124
|
limit,
|
|
121
125
|
ttl,
|
|
@@ -127,9 +131,11 @@ let ThrottlerGuard = class ThrottlerGuard {
|
|
|
127
131
|
timeToBlockExpire,
|
|
128
132
|
});
|
|
129
133
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
if (setHeaders) {
|
|
135
|
+
res.header(`${this.headerPrefix}-Limit${getThrottlerSuffix(throttler.name)}`, limit);
|
|
136
|
+
res.header(`${this.headerPrefix}-Remaining${getThrottlerSuffix(throttler.name)}`, Math.max(0, limit - totalHits));
|
|
137
|
+
res.header(`${this.headerPrefix}-Reset${getThrottlerSuffix(throttler.name)}`, timeToExpire);
|
|
138
|
+
}
|
|
133
139
|
return true;
|
|
134
140
|
}
|
|
135
141
|
async getTracker(req) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttler.guard.js","sourceRoot":"","sources":["../src/throttler.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uCAAyC;AACzC,iCAAgC;AAQhC,+EAAiE;AACjE,+DAO+B;AAC/B,+DAAuF;AACvF,+DAA6E;AAOtE,IAAM,cAAc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CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,oBAAoB,CAAC;gBAC1D,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,OAAyB,EACzB,eAA8B;QAE9B,OAAO,OAAO,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;IAC5F,CAAC;CACF,CAAA;AA7OY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,4CAAsB,GAAE,CAAA;IACxB,WAAA,IAAA,4CAAsB,GAAE,CAAA;qDACK,gBAAS;GAZ9B,cAAc,CA6O1B"}
|
|
@@ -10,7 +10,7 @@ export declare class ThrottlerStorageService implements ThrottlerStorage, OnAppl
|
|
|
10
10
|
private getBlockExpirationTime;
|
|
11
11
|
private setExpirationTime;
|
|
12
12
|
private clearExpirationTimes;
|
|
13
|
-
private
|
|
13
|
+
private resetBlockedRequest;
|
|
14
14
|
private fireHitCount;
|
|
15
15
|
increment(key: string, ttl: number, limit: number, blockDuration: number, throttlerName: string): Promise<ThrottlerStorageRecord>;
|
|
16
16
|
onApplicationShutdown(): void;
|
|
@@ -27,18 +27,18 @@ let ThrottlerStorageService = class ThrottlerStorageService {
|
|
|
27
27
|
const { totalHits } = this.storage.get(key);
|
|
28
28
|
totalHits.set(throttlerName, totalHits.get(throttlerName) - 1);
|
|
29
29
|
clearTimeout(timeoutId);
|
|
30
|
-
this.timeoutIds.set(
|
|
30
|
+
this.timeoutIds.set(key, this.timeoutIds.get(key).filter((id) => id !== timeoutId));
|
|
31
31
|
}, ttlMilliseconds);
|
|
32
|
-
this.timeoutIds.get(
|
|
32
|
+
this.timeoutIds.get(key).push(timeoutId);
|
|
33
33
|
}
|
|
34
|
-
clearExpirationTimes(
|
|
35
|
-
this.timeoutIds.get(
|
|
36
|
-
this.timeoutIds.set(
|
|
34
|
+
clearExpirationTimes(key) {
|
|
35
|
+
this.timeoutIds.get(key).forEach(clearTimeout);
|
|
36
|
+
this.timeoutIds.set(key, []);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
resetBlockedRequest(key, throttlerName) {
|
|
39
39
|
this.storage.get(key).isBlocked = false;
|
|
40
40
|
this.storage.get(key).totalHits.set(throttlerName, 0);
|
|
41
|
-
this.clearExpirationTimes(
|
|
41
|
+
this.clearExpirationTimes(key);
|
|
42
42
|
}
|
|
43
43
|
fireHitCount(key, throttlerName, ttl) {
|
|
44
44
|
const { totalHits } = this.storage.get(key);
|
|
@@ -48,8 +48,8 @@ let ThrottlerStorageService = class ThrottlerStorageService {
|
|
|
48
48
|
async increment(key, ttl, limit, blockDuration, throttlerName) {
|
|
49
49
|
const ttlMilliseconds = ttl;
|
|
50
50
|
const blockDurationMilliseconds = blockDuration;
|
|
51
|
-
if (!this.timeoutIds.has(
|
|
52
|
-
this.timeoutIds.set(
|
|
51
|
+
if (!this.timeoutIds.has(key)) {
|
|
52
|
+
this.timeoutIds.set(key, []);
|
|
53
53
|
}
|
|
54
54
|
if (!this.storage.has(key)) {
|
|
55
55
|
this.storage.set(key, {
|
|
@@ -74,7 +74,7 @@ let ThrottlerStorageService = class ThrottlerStorageService {
|
|
|
74
74
|
}
|
|
75
75
|
const timeToBlockExpire = this.getBlockExpirationTime(key);
|
|
76
76
|
if (timeToBlockExpire <= 0 && this.storage.get(key).isBlocked) {
|
|
77
|
-
this.
|
|
77
|
+
this.resetBlockedRequest(key, throttlerName);
|
|
78
78
|
this.fireHitCount(key, throttlerName, ttlMilliseconds);
|
|
79
79
|
}
|
|
80
80
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttler.service.js","sourceRoot":"","sources":["../src/throttler.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAm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