class Sinatra::ExtendedRack

Some Rack handlers (Thin, 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
179 def call(env)
180   result, callback = app.call(env), env['async.callback']
181   return result unless callback and async?(*result)
182   after_response { callback.call result }
183   setup_close(env, *result)
184   throw :async
185 end

Private Instance Methods

after_response(&block) click to toggle source
    # File lib/sinatra/base.rb
195 def after_response(&block)
196   raise NotImplementedError, "only supports EventMachine at the moment" unless defined? EventMachine
197   EventMachine.next_tick(&block)
198 end
async?(status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
200 def async?(status, headers, body)
201   return true if status == -1
202   body.respond_to? :callback and body.respond_to? :errback
203 end
setup_close(env, status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
189 def setup_close(env, status, headers, body)
190   return unless body.respond_to? :close and env.include? 'async.close'
191   env['async.close'].callback { body.close }
192   env['async.close'].errback { body.close }
193 end