express-slow-down
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -57,5 +57,15 @@ "use strict"; | ||
const delayMs = | ||
typeof options.delayMs === "function" | ||
? options.delayMs(req, res) | ||
: options.delayMs; | ||
const maxDelayMs = | ||
typeof options.maxDelayMs === "function" | ||
? options.maxDelayMs(req, res) | ||
: options.maxDelayMs; | ||
if (current > delayAfter) { | ||
const unboundedDelay = (current - delayAfter) * options.delayMs; | ||
delay = Math.min(unboundedDelay, options.maxDelayMs); | ||
const unboundedDelay = (current - delayAfter) * delayMs; | ||
delay = Math.min(unboundedDelay, maxDelayMs); | ||
} | ||
@@ -62,0 +72,0 @@ |
{ | ||
"name": "express-slow-down", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Basic IP rate-limiting middleware for Express that slows down responses rather than blocking the user.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/nfriedly/express-slow-down", |
@@ -80,3 +80,3 @@ # Express Slow Down | ||
- **windowMs**: milliseconds - how long to keep records of requests in memory. Defaults to `60000` (1 minute). | ||
- **delayAfter**: max number of connections during `windowMs` before starting to delay responses. Number or function that returns a number. Defaults to `1`. Set to `0` to disable delaying. | ||
- **delayAfter**: max number of connections during `windowMs` before starting to delay responses. Number or function that returns a number. Defaults to `1`. | ||
- **delayMs**: milliseconds - how long to delay the response, multiplied by (number of recent hits - `delayAfter`). Defaults to `1000` (1 second). Set to `0` to disable delaying. | ||
@@ -83,0 +83,0 @@ - **maxDelayMs**: milliseconds - maximum value for `delayMs` after many consecutive attempts, that is, after the n-th request, the delay will be always `maxDelayMs`. Important when your application is running behind a load balancer or reverse proxy that has a request timeout. Defaults to `Infinity`. |
12747
163