Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
/ rack-rejector Public archive

A Rack Middleware for Rejecting

License

Notifications You must be signed in to change notification settings

ivx/rack-rejector

Repository files navigation

Unmaintained

This package is unmaintained. If you would like to maintain this package, please get in contact.

Rack::Rejector

This gem is a Rack Middleware to reject requests.

Installation

Add this line to your application's Gemfile:

gem 'rack-rejector'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-rejector

Usage

You still have to write the conditions for rejection on your own. The rest is handled by this gem. It will reject the request if the given block evaluates to true. This example would grant access only to GET requests:

use Rack::Rejector, body: 'No Teapot' do |request, options|
  !request.get?
end

Available options are:

options.body = "I'm a teapot" # Default: '503 SERVICE UNAVAILABLE'
options.code = 418 # Default: 503
options.headers = { 'x-teapot' => 'teapot' } # Default: {}

You can set them either at initialization or override them in the block.

Development

After checking out the repo, run bundle to install dependencies. Then, run bundle exec rake to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ivx/rack-rejector.