express-rate-limit
Advanced tools
Comparing version 2.12.2 to 2.13.0
@@ -66,3 +66,3 @@ "use strict"; | ||
options.store.incr(key, function(err, current) { | ||
options.store.incr(key, function(err, current, resetTime) { | ||
if (err) { | ||
@@ -75,3 +75,4 @@ return next(err); | ||
current: current, | ||
remaining: Math.max(options.max - current, 0) | ||
remaining: Math.max(options.max - current, 0), | ||
resetTime: resetTime | ||
}; | ||
@@ -82,2 +83,14 @@ | ||
res.setHeader("X-RateLimit-Remaining", req.rateLimit.remaining); | ||
if (resetTime) { | ||
// if we have a resetTime, also provide the current date to help avoid issues with incorrect clocks | ||
// format from https://stackoverflow.com/a/13219636/933879 | ||
res.setHeader( | ||
"Date", | ||
new Date() | ||
.toISOString() | ||
.replace(/T/, " ") | ||
.replace(/\..+/, "") | ||
); | ||
res.setHeader("X-RateLimit-Reset", resetTime); | ||
} | ||
} | ||
@@ -84,0 +97,0 @@ |
"use strict"; | ||
function calculateNextResetTime(windowMs) { | ||
return Math.ceil((Date.now() + windowMs) / 1000); | ||
} | ||
function MemoryStore(windowMs) { | ||
var hits = {}; | ||
var resetTime = calculateNextResetTime(windowMs); | ||
@@ -12,3 +18,3 @@ this.incr = function(key, cb) { | ||
cb(null, hits[key]); | ||
cb(null, hits[key], resetTime); | ||
}; | ||
@@ -25,2 +31,3 @@ | ||
hits = {}; | ||
resetTime = calculateNextResetTime(windowMs); | ||
}; | ||
@@ -31,2 +38,3 @@ | ||
delete hits[key]; | ||
delete resetTime[key]; | ||
}; | ||
@@ -33,0 +41,0 @@ |
{ | ||
"name": "express-rate-limit", | ||
"version": "2.12.2", | ||
"version": "2.13.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
15238
156