class Rack::Attack
Constants
- PathNormalizer
- VERSION
Attributes
blacklisted_response[RW]
notifier[RW]
throttled_response[RW]
Public Class Methods
blacklist(name, &block)
click to toggle source
# File lib/rack/attack.rb, line 28 def blacklist(name, &block) self.blacklists[name] = Blacklist.new(name, block) end
blacklisted?(req)
click to toggle source
# File lib/rack/attack.rb, line 51 def blacklisted?(req) blacklists.any? do |name, blacklist| blacklist[req] end end
blacklists()
click to toggle source
# File lib/rack/attack.rb, line 41 def blacklists; @blacklists ||= {}; end
cache()
click to toggle source
# File lib/rack/attack.rb, line 73 def cache @cache ||= Cache.new end
clear!()
click to toggle source
# File lib/rack/attack.rb, line 77 def clear! @whitelists, @blacklists, @throttles, @tracks = {}, {}, {}, {} end
instrument(req)
click to toggle source
# File lib/rack/attack.rb, line 69 def instrument(req) notifier.instrument('rack.attack', req) if notifier end
new(app)
click to toggle source
# File lib/rack/attack.rb, line 91 def initialize(app) @app = app end
throttle(name, options, &block)
click to toggle source
# File lib/rack/attack.rb, line 32 def throttle(name, options, &block) self.throttles[name] = Throttle.new(name, options, block) end
throttled?(req)
click to toggle source
# File lib/rack/attack.rb, line 57 def throttled?(req) throttles.any? do |name, throttle| throttle[req] end end
throttles()
click to toggle source
# File lib/rack/attack.rb, line 42 def throttles; @throttles ||= {}; end
track(name, options = {}, &block)
click to toggle source
# File lib/rack/attack.rb, line 36 def track(name, options = {}, &block) self.tracks[name] = Track.new(name, options, block) end
tracked?(req)
click to toggle source
# File lib/rack/attack.rb, line 63 def tracked?(req) tracks.each_value do |tracker| tracker[req] end end
tracks()
click to toggle source
# File lib/rack/attack.rb, line 43 def tracks; @tracks ||= {}; end
whitelist(name, &block)
click to toggle source
# File lib/rack/attack.rb, line 24 def whitelist(name, &block) self.whitelists[name] = Whitelist.new(name, block) end
whitelisted?(req)
click to toggle source
# File lib/rack/attack.rb, line 45 def whitelisted?(req) whitelists.any? do |name, whitelist| whitelist[req] end end
whitelists()
click to toggle source
# File lib/rack/attack.rb, line 40 def whitelists; @whitelists ||= {}; end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/attack.rb, line 95 def call(env) env['PATH_INFO'] = PathNormalizer.normalize_path(env['PATH_INFO']) req = Rack::Attack::Request.new(env) if whitelisted?(req) @app.call(env) elsif blacklisted?(req) self.class.blacklisted_response.call(env) elsif throttled?(req) self.class.throttled_response.call(env) else tracked?(req) @app.call(env) end end