Class: WebShield::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/web_shield/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
8
# File 'lib/web_shield/middleware.rb', line 5

def initialize(app, config)
  @app = app
  @config = config
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/web_shield/middleware.rb', line 10

def call(env)
  request = Rack::Request.new(env)

  @config.shields.each do |shield|
    result, response = shield.filter(request)

    case result
    when :block
      return @config.blocked_response.call(request)
    when :response
      return response
    when :pass
      if shield.dictatorial?
        # skip other shields
        return @app.call(env)
      end
    else
      # not match
    end
  end

  @app.call(env)
end