Class: RequestStore::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/request_store/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
# File 'lib/request_store/middleware.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/request_store/middleware.rb', line 16

def call(env)
  RequestStore.begin!

  status, headers, body = @app.call(env)

  body = Rack::BodyProxy.new(body) do
    RequestStore.end!
    RequestStore.clear!
  end
  
  returned = true

  [status, headers, body]
ensure
  unless returned
    RequestStore.end!
    RequestStore.clear!
  end
end