Skip to content

A module for rate limiting HTTP(s) requests based on the client IP address.

License

Notifications You must be signed in to change notification settings

cloudkick/rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate-limiter

Rate limiter enables IP address based rate limiting for HTTP(s) requests.

HTTP methods supported:
GET
HEAD
POST
PUT
DELETE
ALL - includes all the supported methods mentioned above

Rate limiter allows you to:

  • Add a new limit for a given path and HTTP method:
    var limiter = new RateLimiter();
    limiter.addLimit('/test-path/', 'GET', 2, 500);
    where,
    '/test-path/' is the path
    'GET' is the HTTP method the limit applies to
    2 is the request count allowed per given period
    500 is the time period for the request in seconds

  • Remove Limit:
    limiter.removeLimit('/test-path/', 'GET');
    where,
    '/test-path/' is the path set on a limit
    'GET' is the HTTP method associated with the path

  • Reset IP address access counter for the given IP address:
    limiter.resetIpAddressAccessCounter('/test-path', 'GET', '127.0.0.1');
    where,
    '/test-path/' is the path set on a limit
    'GET' is the HTTP method associated with the path
    '127.0.0.1' is the IP address for which the counter will be reset

  • Process a request and execute callback if the limit is not reached, else drop the request:
    var sampleReq = {'url': '/test-path/', 'method': 'GET', 'socket': {'remoteAddress': '127.0.0.1'}};
    var sampleRes = {'writeHead': writeHead, 'end': end};
    limiter.processRequest(sampleReq, sampleRes, callback);
    where,
    sampleReq is the request object sampleRes is the response object
    callback is called with request and response if the limit is not reached

Build Status:

Build Status

Tests

npm test

Lint

npm run-script lint

About

A module for rate limiting HTTP(s) requests based on the client IP address.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published