Class: Rack::CloudflareMiddleware::DenyOthers
- Inherits:
-
Object
- Object
- Rack::CloudflareMiddleware::DenyOthers
- Defined in:
- lib/rack/cloudflare_middleware/deny_others.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, allow_private: false, trusted_request_proc: nil, on_fail_proc: nil, trust_xff_if_private: false) ⇒ DenyOthers
constructor
A new instance of DenyOthers.
Constructor Details
#initialize(app, allow_private: false, trusted_request_proc: nil, on_fail_proc: nil, trust_xff_if_private: false) ⇒ DenyOthers
Returns a new instance of DenyOthers.
6 7 8 9 10 11 12 |
# File 'lib/rack/cloudflare_middleware/deny_others.rb', line 6 def initialize(app, allow_private: false, trusted_request_proc: nil, on_fail_proc: nil, trust_xff_if_private: false) @allow_private = allow_private @trusted_request_proc = trusted_request_proc @on_fail_proc = on_fail_proc @trust_xff_if_private = trust_xff_if_private @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/cloudflare_middleware/deny_others.rb', line 14 def call(env) TrustedIps.instance.check_update remote_addr = Rack::CloudflareMiddleware.get_remote_addr(env, @trust_xff_if_private) if (@allow_private && (remote_addr.private? || remote_addr.loopback?)) || TrustedIps.instance.include?(remote_addr) || @trusted_request_proc&.call(Rack::Request.new(env)) @app.call(env) elsif @on_fail_proc.nil? default_on_fail(remote_addr) else @on_fail_proc.call(env) end end |