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
193 def call(env)
194   result, callback = app.call(env), env['async.callback']
195   return result unless callback and async?(*result)
196   after_response { callback.call result }
197   setup_close(env, *result)
198   throw :async
199 end

Private Instance Methods

after_response(&block) click to toggle source
    # File lib/sinatra/base.rb
209 def after_response(&block)
210   raise NotImplementedError, "only supports EventMachine at the moment" unless defined? EventMachine
211   EventMachine.next_tick(&block)
212 end
async?(status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
214 def async?(status, headers, body)
215   return true if status == -1
216   body.respond_to? :callback and body.respond_to? :errback
217 end
setup_close(env, status, headers, body) click to toggle source
    # File lib/sinatra/base.rb
203 def setup_close(env, status, headers, body)
204   return unless body.respond_to? :close and env.include? 'async.close'
205   env['async.close'].callback { body.close }
206   env['async.close'].errback { body.close }
207 end