0.0
No commit activity in last 3 years
No release in over 3 years
Rack middleware rate limiter that provides both time-based limits and quantity-based limits
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.0.3
>= 1.5
>= 0.6
 Project Readme

Rack::Congestion

Build Status Test Coverage Code Climate Gem Version

Rack middleware for Congestion

Provides rate limiting for Rack-based applications.

Installation

Add this line to your application's Gemfile:

gem 'rack-congestion'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-congestion

Usage

The available limiters are:

  • Rack::Congestion::Limiter
    • Application-wide limiting
  • Rack::Congestion::IpLimiter
    • Limits requests per-IP
  • Rack::Congestion::PathLimiter
    • Limits requests for a path segment
    • e.g. limit requests to '/api'
    • accepts path:(required) and path_matcher:(optional) options

Examples and more advanced usage can be found in examples

Documentation of Congestion configuration can be found here

In a Rack application

require 'rack/congestion'

# Limit requests to
#   - a maximum of 100 requests per minute
#   - a maximum rate of 1 request every 100 milliseconds
use Rack::Congestion::IpLimiter, interval: 60, max_in_interval: 100, min_delay: 0.1

run ->(env){
  [200, { 'Content-Type' => 'text/plain' }, ['Hello world']]
}

In a Rails application

# config/application.rb
require 'rack/congestion'

class YourApplication < Rails::Application
  config.middleware.use Rack::Congestion::IpLimiter
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To run the specs, run bundle exec rake.

Contributing

  1. Fork it ( https://github.com/parrish/rack-congestion/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request