class RequestStore::Middleware

Public Class Methods

new(app) click to toggle source
# File lib/request_store/middleware.rb, line 12
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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