Class: Rack::Dedos::Filters::UserAgent
- Defined in:
- lib/rack/dedos/filters/user_agent.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #allowed?(request, ip) ⇒ Boolean
-
#initialize ⇒ UserAgent
constructor
A new instance of UserAgent.
Methods inherited from Base
Constructor Details
#initialize ⇒ UserAgent
Returns a new instance of UserAgent.
11 12 13 14 15 16 17 |
# File 'lib/rack/dedos/filters/user_agent.rb', line 11 def initialize(*) super @cache_url = [:cache_url] or fail "cache URL not set" @cache_period = [:cache_period] || 900 @cache_key_prefix = [:cache_key_prefix] cache # hit once to fail on errors at boot end |
Instance Method Details
#allowed?(request, ip) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rack/dedos/filters/user_agent.rb', line 19 def allowed?(request, ip) case cache.get(ip) when nil # first contact cache.set(ip, request.user_agent) true when 'BLOCKED' # already blocked false when request.user_agent # user agent hasn't changed true else # user agent has changed cache.set(ip, 'BLOCKED') false end rescue => error warn("rack-dedos: request from #{ip} allowed due to error: #{error.}") true end |