express-rate-limit
Advanced tools
Comparing version 2.3.1 to 2.4.0
@@ -15,2 +15,3 @@ 'use strict'; | ||
statusCode: 429, // 429 status = Too Many Requests (RFC 6585) | ||
headers: true, //Send custom rate limit header with limit and remaining | ||
// allows to create custom keys (by default user IP is used) | ||
@@ -32,3 +33,2 @@ keyGenerator: function (req /*, res*/) { | ||
// store to use for persisting rate limit data | ||
@@ -53,16 +53,27 @@ options.store = options.store || new MemoryStore(options.windowMs); | ||
options.store.incr(key, function(err, current) { | ||
if (err) { | ||
return next(err); | ||
} | ||
if (err) { | ||
return next(err); | ||
} | ||
if (options.max && current > options.max) { | ||
return options.handler(req,res, next); | ||
} | ||
req.rateLimit = { | ||
limit: options.max, | ||
remaining: Math.max(options.max - current, 0) | ||
}; | ||
if (options.headers) { | ||
res.setHeader('X-RateLimit-Limit', options.max); | ||
res.setHeader('X-RateLimit-Remaining', req.rateLimit.remaining); | ||
} | ||
if (options.delayAfter && options.delayMs && current > options.delayAfter) { | ||
if (options.max && current > options.max) { | ||
return options.handler(req, res, next); | ||
} | ||
if (options.delayAfter && options.delayMs && current > options.delayAfter) { | ||
var delay = (current - options.delayAfter) * options.delayMs; | ||
setTimeout(next, delay); | ||
} else { | ||
next(); | ||
} | ||
return setTimeout(next, delay); | ||
} | ||
next(); | ||
}); | ||
@@ -69,0 +80,0 @@ } |
{ | ||
"name": "express-rate-limit", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/nfriedly/express-rate-limit", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
11569
4
89
0
167