Class: Chassis::Rack::Bouncer
- Inherits:
-
Object
- Object
- Chassis::Rack::Bouncer
- Defined in:
- lib/chassis/rack/bouncer.rb
Constant Summary collapse
- BOUNCERS =
[ lambda { |req| ; req.user_agent =~ /masscan/ } ]
Instance Method Summary collapse
- #bounce?(env) ⇒ Boolean
- #bouncers ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, &bouncer) ⇒ Bouncer
constructor
A new instance of Bouncer.
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
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 |
#bouncers ⇒ Object
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 |