class WebShield::Middleware

Public Class Methods

new(app, config) click to toggle source
# File lib/web_shield/middleware.rb, line 5
def initialize(app, config)
  @app = app
  @config = config
end

Public Instance Methods

call(env) click to toggle source
# 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