No commit activity in last 3 years
No release in over 3 years
Add RateLimit headers for Rack::Attack throttling
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

>= 0
 Project Readme

Rack::Attack::RateLimit

Build Status

Add rate limit headers for Rack::Attack throttles.

Installation

Install the gem:

gem install 'rack-attack-rate-limit'

In your gemfile:

gem 'rack-attack-rate-limit', require: 'rack/attack/rate-limit'

And then execute:

bundle

Usage

Rack::Attack::RateLimit expects at least one Rack::Attack throttle to be defined:

Rack::Attack.throttle('my_throttle') do |req|
  req.ip
end

To include rate limit headers for throttles, include the Rack::Attack::RateLimit middleware, and provide it with the names of the throttles you want to add rate limit headers for. A single throttle name can be provided as a string, while multiple throttle names must be provided as an array of strings.

For Rails 3+:

config.middleware.use Rack::Attack::RateLimit, throttle: ['my_throttle', 'my_other_throttle']

Rate limit headers are:

  • 'X-RateLimit-Limit' - The total number of requests allowed.
  • 'X-RateLimit-Remaining' - The number of remaining requests.

If a request triggers multiple throttles, the gem will add headers for the throttle with the lowest number of remaining requests.

Contributing

  1. Fork it
  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 new Pull Request