GithubHelp home page GithubHelp logo

stop_it's Introduction

Stop It

Build Status Code Climate Test Coverage

Stop It is a middleware for blocking requests to rake apps.

Installation

Add this line to your application's Gemfile:

gem 'stop_it'

And then execute:

$ bundle

Or install it yourself as:

$ gem install stop_it

Usage

Let's see how to use Stop It with Ruby on Rails apps. To insert Stop It into the stack of middlewares of your app open config.ru file and add line

use StopIt

right after line

require ::File.expand_path('../config/environment',  __FILE__)

so that the file contains code similar to this:

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
use StopIt
run MyRailsApp::Application # Here should be your application class name

To configure which requests should be stopped add config/initializers/stop_it.rb file to your Ruby on Rails app with the following content:

StopIt.stop do |opts|

end

opts is a hash with the following keys: path_info, remote_addr, query_string, request_method, http_user_agent.

If the block in stop method returns true then the request will be blocked. If it returns false then the request will be passed to the next middleware. In the following example all requests to /forbidden will be blocked.

StopIt.stop do |opts|
  opts[:path_info] == '/forbidden'
end

Requests can be blocked by request path, remote address, query string, HTTP method, and user agent.

The block in stop method may return a rake app response like this:

StopIt.stop do |opts|
  if opts[:remote_addr] == '127.0.0.2'
    [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
  end
end

In this case the request will be blocked and the requestor will receive the returned response.

Contributing

Your contribution is welcome.

stop_it's People

Contributors

andrewgr avatar

Stargazers

Jordan avatar Sergey Ermolaev avatar shuo zhao avatar Andrew avatar Yury Batenko avatar  avatar Jacek Pakulski avatar Sergey Moiseev avatar Yury Trofimenko avatar Ivan Dymkov avatar Kirill Chernyshov avatar

Watchers

James Cloos avatar wercker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.