mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Better cache interface
This commit is contained in:
parent
e135f17386
commit
6784f21612
2 changed files with 6 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ module Rack::Attack
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
attr_accessor :cache, :notifier, :blacklisted_response, :throttled_response
|
attr_accessor :notifier, :blacklisted_response, :throttled_response
|
||||||
|
|
||||||
def whitelist(name, &block)
|
def whitelist(name, &block)
|
||||||
self.whitelists[name] = Whitelist.new(name, block)
|
self.whitelists[name] = Whitelist.new(name, block)
|
||||||
|
|
@ -29,7 +29,6 @@ module Rack::Attack
|
||||||
@app = app
|
@app = app
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
@cache ||= Cache.new
|
|
||||||
@notifier ||= ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
@notifier ||= ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
||||||
@blacklisted_response ||= lambda {|env| [503, {}, ['Blocked']] }
|
@blacklisted_response ||= lambda {|env| [503, {}, ['Blocked']] }
|
||||||
@throttled_response ||= lambda {|env|
|
@throttled_response ||= lambda {|env|
|
||||||
|
|
@ -78,6 +77,10 @@ module Rack::Attack
|
||||||
notifier.instrument('rack.attack', req) if notifier
|
notifier.instrument('rack.attack', req) if notifier
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache
|
||||||
|
@cache ||= Cache.new
|
||||||
|
end
|
||||||
|
|
||||||
def clear!
|
def clear!
|
||||||
@whitelists, @blacklists, @throttles = {}, {}, {}
|
@whitelists, @blacklists, @throttles = {}, {}, {}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module Rack
|
module Rack
|
||||||
module Attack
|
module Attack
|
||||||
VERSION = '1.1.0'
|
VERSION = '1.2.0'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue