Class: Chassis::Rack::Bouncer

Inherits:
Object
  • Object
show all
Defined in:
lib/chassis/rack/bouncer.rb

Constant Summary collapse

BOUNCERS =
[
  lambda { |req| ; req.user_agent =~ /masscan/ }
]

Instance Method Summary collapse

Constructor Details

#initialize(app, &bouncer) ⇒ Bouncer

Returns a new instance of Bouncer.



8
9
10
# File 'lib/chassis/rack/bouncer.rb', line 8

def initialize(app, &bouncer)
  @app, @bouncer = app, bouncer
end

Instance Method Details

#bounce?(env) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/chassis/rack/bouncer.rb', line 20

def bounce?(env)
  request = ::Rack::Request.new env

  bouncers.any? do |bouncer|
    bouncer.call request
  end
end

#bouncersObject



28
29
30
# File 'lib/chassis/rack/bouncer.rb', line 28

def bouncers
  [BOUNCERS, @bouncer].flatten.compact
end

#call(env) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/chassis/rack/bouncer.rb', line 12

def call(env)
  if bounce?(env)
    [403, { }, [ ]]
  else
    @app.call env
  end
end