class Sinatra::ExtendedRack

Some Rack handlers (Rainbows!) implement an extended body object protocol, however, some middleware (namely Rack::Lint) will break it by not mirroring the methods in question. This middleware will detect an extended body object and will make sure it reaches the handler directly. We do this here, so our middleware and middleware set up by the app will still be able to run.

Public Instance Methods

call(env) click to toggle source
    # File lib/sinatra/base.rb
215 def call(env)
216   result, callback = app.call(env), env['async.callback']
217   return result unless callback and async?(*result)
218   after_response { callback.call result }
219   setup_close(env, *result)
220   throw :async
221 end

Private Instance Methods

after_response(&block) click to toggle source
    # File lib/sinatra/base.rb
231 def after_response(&block)
232   raise NotImplementedError, "only supports EventMachine at the moment" unless defined? EventMachine
233   EventMachine.next_tick(&block)
234 end
async?(status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
236 def async?(status, headers, body)
237   return true if status == -1
238   body.respond_to? :callback and body.respond_to? :errback
239 end
setup_close(env, status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
225 def setup_close(env, status, headers, body)
226   return unless body.respond_to? :close and env.include? 'async.close'
227   env['async.close'].callback { body.close }
228   env['async.close'].errback { body.close }
229 end