class Da99_Rack_Protect

Constants

DA99
Ignore_Rack_Protects
Known_Rack_Protects
Names
RACK_PROTECTS
RACK_PROTECTS_DIR

I need to know if new middleware has been added to ‘rack-protection` so it can be properly used (or ignored) by Da99_Rack_Protect.

Rack_Protection_Names
Unknown_Rack_Protects

Public Class Methods

new(main_app) { |self| ... } click to toggle source
# File lib/da99_rack_protect.rb, line 83
def initialize main_app
  @configs = configs = {:hosts=>[]}

  yield(self) if block_given?

  @app = Rack::Builder.new do

    use Rack::Lint
    use Rack::ContentLength
    use Rack::ContentType, "text/plain"
    use Rack::MethodOverride
    use Rack::Session::Cookie, secret: SecureRandom.urlsafe_base64(nil, true)

    Known_Rack_Protects.each { |name|
      use Rack::Protection.const_get(Rack_Protection_Names[name])
    }

    Names.each { |name|
      case name
      when :Ensure_Host
        use Da99_Rack_Protect.const_get(name), *(configs[:hosts])
      else
        use Da99_Rack_Protect.const_get(name)
      end
    }

    run main_app
  end

  @configs[:hosts].freeze
end
redirect(new, code = 301) click to toggle source
# File lib/da99_rack_protect.rb, line 65
def redirect new, code = 301
  res = Rack::Response.new
  res.redirect new, code
  res.finish
end
response(code, type, raw_content) click to toggle source
# File lib/da99_rack_protect.rb, line 71
def response code, type, raw_content
  content = raw_content.to_s
  res = Rack::Response.new
  res.status = code.to_i
  res.headers['Content-Length'] = content.bytesize.to_s
  res.headers['Content-Type']   = 'text/plain'.freeze
  res.body = [content]
  res.finish
end

Public Instance Methods

call(env) click to toggle source
# File lib/da99_rack_protect.rb, line 126
def call env
  @app.call env
end
config(settings, *args) click to toggle source
# File lib/da99_rack_protect.rb, line 115
def config settings, *args
  case settings
  when :host
    @configs[:hosts].concat args
  else
    fail "Unknown args: #{args.inspect}"
  end # === case

  self
end