Class: MaybeLater::Middleware
- Inherits:
-
Object
- Object
- MaybeLater::Middleware
- Defined in:
- lib/maybe_later/middleware.rb
Constant Summary collapse
- RACK_AFTER_REPLY =
"rack.after_reply"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
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 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/maybe_later/middleware.rb', line 9 def call(env) config = MaybeLater.config status, headers, body = @app.call(env) if Store.instance.callbacks.any? if env.key?(RACK_AFTER_REPLY) env[RACK_AFTER_REPLY] << -> { RunsCallbacks.new.call } elsif !config.invoke_even_if_server_is_unsupported warn <<~MSG This server may not support '#{RACK_AFTER_REPLY}' callbacks. To ensure that your tasks are executed, consider enabling: config.invoke_even_if_server_is_unsupported = true Note that this option, when combined with `inline: true` can result in delayed flushing of HTTP responses by the server (defeating the purpose of the gem. MSG else RunsCallbacks.new.call end if Store.instance.callbacks.any? { |cb| cb.inline } headers["Connection"] = "close" end end [status, headers, body] end |