Class: Rack::IpRestrictor::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_ip_restrictor/middleware.rb

Overview

Rack middleware

Instance Method Summary (collapse)

Constructor Details

- (Middleware) initialize(app, options = {})



4
5
6
7
# File 'lib/rack_ip_restrictor/middleware.rb', line 4

def initialize(app, options={})
  @app = app
  @options = options
end

Instance Method Details

- (Object) call(env)

Rack middleware call method



10
11
12
13
14
15
16
17
18
# File 'lib/rack_ip_restrictor/middleware.rb', line 10

def call(env)
  remote_addr = IPAddr.new(env['REMOTE_ADDR'])

  Rack::IpRestrictor.config.restrictions.each do |restriction|
    return access_denied unless restriction.validate(env, remote_addr)
  end

  @app.call(env)
end