Home

Awesome

rack-block

A rack middleware for controlling accesses by search bot or not, remote ip address, etc.

Install

    $ gem install rack-block

No doubt it depends on rack (>= 1.3).

Usage

block all bot accesses:

    use Rack::Block do
      bot_access do
        halt 404
      end
    end
    run App.new

block all bot accesses on a specific path:

    use Rack::Block do
      bot_access do
        path '/secret/*' do
          halt 404
        end
      end
    end
    run App.new

block some patterns of accesses:

    use Rack::Block do
      ua_pattern /googlebot/i do
        halt 404
      end
    end
    run App.new

block accesses from specific IP(s):

    use Rack::Block do
      ip_pattern '192.0.0.0' do
      # expressions like '192.0.0.' also available
        halt 404
      end
    end
    run App.new

redirect accesses:

    use Rack::Block do
      bot_access do
        path '/secret/*' do
          redirect '/'
        end
      end
    end
    run App.new

redirect accesses to a double app:

    use Rack::Block do
      bot_access do
        path '/secret/*' do
          # TheDummy is a Rack-compatible app
          double { TheDummy.new }
        end
      end
    end
    run App.new

More usage on RDoc: [http://rubydoc.info/github/udzura/rack-block/master/frames]

Or please look into spec/*

Related Sites

Todo

Contributing to rack-block

Copyright

Copyright (c) 2011 Uchio Kondo udzura@udzura.jp. See LICENSE for further details.