Rack::Berater
Limit incoming Rack requests with Berater.
Basic Usage
Transform limit errors into HTTP status code 429
require 'rack/berater/railtie'Customized Response
Customize the rack response returned when a limit error occurs:
-
status_code- which HTTP status code -
body- what message -
headers- hash of headers
require 'rack/berater'
Rails.application.middleware.use(Rack::Berater, status_code: 503, body: 'slow down yo')Enforce Limits
Add a limiter to every incoming rack request.
require 'rack/berater'
Rails.application.middleware.use(Rack::Berater, limiter: Berater::ConcurrencyLimiter.new(key, capacity))Custom Error Types
Register exceptions to be handled by Rack::Berater
Rack::Berater::ERRORS << NoMemoryErrorContributing
Yes please :)
- Fork it
- Create your feature branch (
git checkout -b my-feature) - Ensure the tests pass (
bundle exec rspec) - Commit your changes (
git commit -am 'awesome new feature') - Push your branch (
git push origin my-feature) - Create a Pull Request