Class: Rack::Dedos::Filters::Base
- Inherits:
-
Object
- Object
- Rack::Dedos::Filters::Base
- Defined in:
- lib/rack/dedos/filters/base.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ logger: nil, cache_url: 'Hash', cache_key_prefix: nil, only_paths: [], except_paths: [], status: 403, text: 'Forbidden (Temporarily Blocked by Rules)', headers: [] }.freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(app, options = {}) ⇒ Base
Returns a new instance of Base.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/dedos/filters/base.rb', line 25 def initialize(app, ={}) @app = app @options = DEFAULT_OPTIONS.merge() @cache = Cache.new( url: @options[:cache_url], key_prefix: @options[:cache_key_prefix] ) @logger ||= [:logger] || ::Logger.new($stdout, progname: 'rack-dedos') @details = {} end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
21 22 23 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def app @app end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
21 22 23 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def cache @cache end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
21 22 23 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def details @details end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
21 22 23 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def @options end |
Instance Method Details
#call(env) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rack/dedos/filters/base.rb', line 36 def call(env) request = Rack::Request.new(env) ip = real_ip(request) if !apply?(request) || allowed?(request, ip) app.call(env) else = ["request #{request.path} from #{ip} blocked by #{name}"] += details_list += headers_list(request) logger.info(.join(' ')) [[:status], { 'Content-Type' => 'text/plain' }, [[:text]]] end end |