2 # can't use non-compatible middleware that doesn't pass "deferered?" calls
4 # used for testing deferred actions for Merb and possibly other frameworks
5 # ref: http://brainspl.at/articles/2008/04/18/deferred-requests-with-merb-ebb-and-thin
7 class DeferredApp < Struct.new(:app)
9 env["PATH_INFO"] =~ %r{\A/deferred}
13 env["rack.multithread"] or raise RuntimeError, "rack.multithread not true"
14 body = "#{Thread.current.inspect}\n"
15 if env["PATH_INFO"] =~ %r{\A/deferred(\d+)}
17 File.open(ENV['fifo'], 'w') { |fp| fp.write "sleeping #{delay}s\n" }
18 body = "deferred sleep\n"
22 "Content-Type" => "text/plain",
23 "Content-Length" => body.size.to_s,
25 [ 200, headers, [ body ] ]