Class: WebShield::ThrottleShield
- Defined in:
- lib/web_shield/throttle_shield.rb
Constant Summary
Constants inherited from Shield
Instance Attribute Summary
Attributes inherited from Shield
#config, #id, #options, #path_matcher, #shield_path
Instance Method Summary collapse
Methods inherited from Shield
Constructor Details
This class inherits a constructor from WebShield::Shield
Instance Method Details
#filter(request) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/web_shield/throttle_shield.rb', line 6 def filter(request) req_path = request.path return unless path_matcher.match(req_path) return :block if [:limit] <= 0 return if [:method] && [:method].to_s.upcase != request.request_method user = config.user_parser.call(request) store_keys = [id.to_s, user.to_s] if [:path_sensitive] route = [request.request_method, req_path] else route = ([:method] ? [[:method].to_s.upcase, shield_path] : [shield_path]) end store_keys << Digest::MD5.hexdigest(route.join('-')) if @config.store.incr(store_keys.join('-'), [:period]) <= [:limit] :pass else config.logger.info("[#{id}] Block '#{user}' #{request.request_method} #{req_path}") :block end end |