Class: RequestStoreRails::Middleware
- Inherits:
-
Object
- Object
- RequestStoreRails::Middleware
- Defined in:
- lib/request_store_rails/middleware.rb
Overview
Public: Middleware that takes care of setting the thread-local variable :request_id, which enables RequestLocals to associate threads and requests.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Internal: Assigns the :request_id thread-local variable, and cleans up all the request-local variables after the request.
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 |
# File 'lib/request_store_rails/middleware.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Internal: Assigns the :request_id thread-local variable, and cleans up all the request-local variables after the request.
15 16 17 18 19 20 21 |
# File 'lib/request_store_rails/middleware.rb', line 15 def call(env) Thread.current[:request_id] = extract_request_id(env) @app.call(env) ensure RequestLocals.clear! Thread.current[:request_id] = nil end |