Class: Rack::Cloudflare::Middleware::AccessControl

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/cloudflare/middleware/access_control.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AccessControl

Returns a new instance of AccessControl.



16
17
18
# File 'lib/rack/cloudflare/middleware/access_control.rb', line 16

def initialize(app)
  @app = app
end

Class Attribute Details

.blocked_messageObject

Returns the value of attribute blocked_message.



8
9
10
# File 'lib/rack/cloudflare/middleware/access_control.rb', line 8

def blocked_message
  @blocked_message
end

.blocked_responseObject

Returns the value of attribute blocked_response.



8
9
10
# File 'lib/rack/cloudflare/middleware/access_control.rb', line 8

def blocked_response
  @blocked_response
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/cloudflare/middleware/access_control.rb', line 20

def call(env)
  headers = Headers.new(env)

  if headers.trusted?
    Cloudflare.info "[#{self.class.name}] Trusted Network (REMOTE_ADDR): #{headers.target_headers}"
    @app.call(env)
  else
    Cloudflare.warn "[#{self.class.name}] Untrusted Network (REMOTE_ADDR): #{headers.target_headers}"
    AccessControl.blocked_response.call(env)
  end
end