Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-rate-limit

Package Overview
Dependencies
Maintainers
13
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-rate-limit - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0

8

index.js

@@ -9,4 +9,2 @@ 'use strict'

const routeRateAdded = Symbol('fastify-rate-limit.routeRateAdded')
let labels = {

@@ -124,8 +122,2 @@ rateLimit: 'x-ratelimit-limit',

async function buildRouteRate (pluginComponent, params, routeOptions) {
if (routeOptions[routeRateAdded]) {
return
}
routeOptions[routeRateAdded] = true
const after = ms(params.timeWindow, { long: true })

@@ -132,0 +124,0 @@

2

package.json
{
"name": "fastify-rate-limit",
"version": "5.2.0",
"version": "5.3.0",
"description": "A low overhead rate limiter for your routes",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -980,2 +980,63 @@ 'use strict'

test('Allow multiple different rate limiter registrations', t => {
t.plan(20)
const fastify = Fastify()
fastify.register(rateLimit, {
max: 1,
timeWindow: 1000,
whitelist: (req) => {
return req.url !== '/test'
}
})
fastify.register(rateLimit, {
max: 1,
timeWindow: 1000,
whitelist: (req) => {
return req.url === '/test'
}
})
fastify.get('/', (req, reply) => {
reply.send('hello!')
})
fastify.get('/test', (req, reply) => {
reply.send('hello from another route!')
})
fastify.inject('/', (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['x-ratelimit-limit'], 1)
t.strictEqual(res.headers['x-ratelimit-remaining'], 0)
fastify.inject('/', (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 429)
t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
t.strictEqual(res.headers['x-ratelimit-limit'], 1)
t.strictEqual(res.headers['x-ratelimit-remaining'], 0)
t.strictEqual(res.headers['retry-after'], 1000)
})
})
fastify.inject('/test', (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['x-ratelimit-limit'], 1)
t.strictEqual(res.headers['x-ratelimit-remaining'], 0)
fastify.inject('/test', (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 429)
t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
t.strictEqual(res.headers['x-ratelimit-limit'], 1)
t.strictEqual(res.headers['x-ratelimit-remaining'], 0)
t.strictEqual(res.headers['retry-after'], 1000)
})
})
})
test('With enable IETF draft spec', t => {

@@ -982,0 +1043,0 @@ t.plan(5)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc