Class: Rack::SimpleCsrf
- Inherits:
-
Object
- Object
- Rack::SimpleCsrf
- Defined in:
- lib/rack/simple_csrf.rb,
lib/rack/simple_csrf/version.rb
Defined Under Namespace
Modules: Helpers Classes: CSRFFailedToValidateError, CSRFSessionUnavailableError
Constant Summary collapse
- VERSION =
"1.3.0"
Instance Method Summary collapse
- #call(env, req = Rack::Request.new(env)) ⇒ Object
-
#initialize(app, opts = {}) ⇒ SimpleCsrf
constructor
A new instance of SimpleCsrf.
Constructor Details
#initialize(app, opts = {}) ⇒ SimpleCsrf
Returns a new instance of SimpleCsrf.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rack/simple_csrf.rb', line 24 def initialize(app, opts = {}) @field = opts.fetch(:field, "auth") @raise = opts.fetch(:raise, false) @key = opts.fetch(:key, "csrf") @skip = opts.fetch(:skip, []) @app = app @render_with = opts[:render_with] @header = opts.fetch(:header, "HTTP_X_CSRF_TOKEN") @methods = (%w(POST PUT DELETE PATCH) + \ opts.fetch(:http_methods, [])).flatten.uniq end |
Instance Method Details
#call(env, req = Rack::Request.new(env)) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rack/simple_csrf.rb', line 38 def call(env, req = Rack::Request.new(env)) raise_if_session_unavailable_for! req setup_csrf_for! req return @app.call(env) if continue?(req) @raise ? raise(CSRFFailedToValidateError) : render_error_for!(env) end |