Object
# File lib/rack/protection/base.rb, line 18 def self.default_options(options) define_method(:default_options) { super().merge(options) } end
# File lib/rack/protection/base.rb, line 38 def accepts?(env) raise NotImplementedError, "#{self.class} implementation pending" end
# File lib/rack/protection/base.rb, line 42 def call(env) unless accepts? env warn env, "attack prevented by #{self.class}" result = react env end result or app.call(env) end
# File lib/rack/protection/base.rb, line 26 def default_options DEFAULT_OPTIONS end
# File lib/rack/protection/base.rb, line 61 def deny(env) [options[:status], {'Content-Type' => 'text/plain'}, [options[:message]]] end
# File lib/rack/protection/base.rb, line 74 def drop_session(env) session(env).clear if session? env end
# File lib/rack/protection/base.rb, line 90 def encrypt(value) options[:encryptor].hexdigest value.to_s end
# File lib/rack/protection/base.rb, line 84 def random_string(secure = defined? SecureRandom) secure ? SecureRandom.hex(32) : "%032x" % rand(2**128-1) rescue NotImplementedError random_string false end
# File lib/rack/protection/base.rb, line 50 def react(env) result = send(options[:reaction], env) result if Array === result and result.size == 3 end
# File lib/rack/protection/base.rb, line 78 def referrer(env) ref = env['HTTP_REFERER'].to_s return if !options[:allow_empty_referrer] and ref.empty? URI.parse(ref).host || Request.new(env).host end
# File lib/rack/protection/base.rb, line 34 def safe?(env) ]GET HEAD OPTIONS TRACE].include? env['REQUEST_METHOD'] end
# File lib/rack/protection/base.rb, line 69 def session(env) return env[options[:session_key]] if session? env fail "you need to set up a session middleware *before* #{self.class}" end
Generated with the Darkfish Rdoc Generator 2.