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, 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.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#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.
23 24 25 26 27 |
# File 'lib/rack/dedos/filters/base.rb', line 23 def initialize(app, ={}) @app = app = DEFAULT_OPTIONS.merge() @details = {} end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
19 20 21 |
# File 'lib/rack/dedos/filters/base.rb', line 19 def app @app end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
19 20 21 |
# File 'lib/rack/dedos/filters/base.rb', line 19 def details @details end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/rack/dedos/filters/base.rb', line 19 def end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/dedos/filters/base.rb', line 29 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 |