class Goliath::Rack::SimpleAroundwareFactory


@see Goliath::Rack::BarrierAroundware
@see Goliath::Rack::SimpleAroundware
@see Goliath::Rack::AsyncMiddleware
longer applies, as each aroundware is unique per request.
also lets you carry state around – the ban on instance variables no
request by walking up the callback chain. Delegating out to the aroundware
processing. Goliath proceeds asynchronously, but will still “unwind” the
This class creates a “aroundware” helper to do that kind of
end
[status, headers, new_body]
new_body = make_totally_awesome(body) ## !! BROKEN !!
status, headers, body = @app.call(env)
# … do pre-processing
def call(env)
For internal reasons, you can’t do the following as you would in Rack:
post-processing.
Include this to enable middleware that can perform pre- and

def call(env)

Returns:
  • (Array) - The [status_code, headers, body] tuple

Parameters:
  • env (Goliath::Env) -- The goliath environment
def call(env)
  aroundware = new_aroundware(env)
  aroundware_resp = aroundware.pre_process
  return aroundware_resp if final_response?(aroundware_resp)
  hook_into_callback_chain(env, aroundware)
  downstream_resp = @app.call(env)
  # if downstream resp is final, pass it to the aroundware; it will invoke
  # the callback chain at its leisure. Our response is *always* async.
  if final_response?(downstream_resp)
    aroundware.accept_response(:downstream_resp, true, downstream_resp)
  end
  return Goliath::Connection::AsyncResponse
end

def final_response?(resp)

def final_response?(resp)
  resp != Goliath::Connection::AsyncResponse
end

def hook_into_callback_chain(env, aroundware)

* set the old callback chain to fire when the aroundware completes
completing it)
* have the downstream callback send results to the aroundware (possibly
* save the old callback chain;
Put aroundware in the middle of the async_callback chain:
def hook_into_callback_chain(env, aroundware)
  async_callback = env['async.callback']
  # The response from the downstream app is accepted by the aroundware...
  # ... and we immediately call post_process and hand it upstream
  downstream_callback = Proc.new do |resp|
    safely(env){ aroundware.accept_response(:downstream_resp, true, resp) }
    new_resp = safely(env){ aroundware.post_process }
    async_callback.call(new_resp)
  end
  env['async.callback'] = downstream_callback
end

def initialize app, aroundware_klass, *args

Returns:
  • (Goliath::Rack::AroundwareFactory) -

Parameters:
  • *args (Array) -- extra args to pass to the aroundware
  • aroundware_klass () -- a class that quacks like a
  • app (#call) -- the downstream app
def initialize app, aroundware_klass, *args
  @app = app
  @aroundware_klass = aroundware_klass
  @aroundware_args  = args
end

def new_aroundware(env)

Returns:
  • (Goliath::Rack::SimpleAroundware) - The aroundware to process this request

Parameters:
  • env (Goliath::Env) -- The goliath environment
def new_aroundware(env)
  @aroundware_klass.new(env, *@aroundware_args)
end