Class: MaybeLater::Middleware

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

Constant Summary collapse

RACK_AFTER_REPLY =
"rack.after_reply"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
# File 'lib/maybe_later/middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/maybe_later/middleware.rb', line 9

def call(env)
  status, headers, body = @app.call(env)
  if Store.instance.any_callbacks?
    env[RACK_AFTER_REPLY] ||= []
    env[RACK_AFTER_REPLY] << -> {
      RunsCallbacks.new.call
    }
    headers["Connection"] = "close"
  end
  [status, headers, body]
end