Class: InertiaRails::Middleware::InertiaRailsRequest
- Inherits:
-
Object
- Object
- InertiaRails::Middleware::InertiaRailsRequest
- Defined in:
- lib/inertia_rails/middleware.rb
Instance Method Summary collapse
-
#initialize(app, env) ⇒ InertiaRailsRequest
constructor
A new instance of InertiaRailsRequest.
- #response ⇒ Object
Constructor Details
#initialize(app, env) ⇒ InertiaRailsRequest
Returns a new instance of InertiaRailsRequest.
14 15 16 17 |
# File 'lib/inertia_rails/middleware.rb', line 14 def initialize(app, env) @app = app @env = env end |
Instance Method Details
#response ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/inertia_rails/middleware.rb', line 19 def response copy_xsrf_to_csrf! status, headers, body = if prevent_precognition_writes? ActiveRecord::Base.while_preventing_writes { @app.call(@env) } else @app.call(@env) end request = ActionDispatch::Request.new(@env) # Inertia session data is added via redirect_to # Guard with session.loaded? to avoid forcing session I/O (and unnecessary # database writes) on requests that never accessed the session, e.g. sessionless # controllers. If the session was never loaded the Inertia keys cannot have been # set, so the cleanup would be a no-op anyway. unless (status) || !request.session.loaded? request.session.delete(:inertia_errors) request.session.delete(:inertia_clear_history) request.session.delete(:inertia_preserve_fragment) end status = 303 if inertia_non_post_redirect?(status) stale_inertia_get? ? force_refresh(request) : [status, headers, body] end |