class Sinatra::ExtendedRack

Some Rack handlers 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
226 def call(env)
227   result = app.call(env)
228   callback = env['async.callback']
229   return result unless callback && async?(*result)
230 
231   after_response { callback.call result }
232   setup_close(env, *result)
233   throw :async
234 end

Private Instance Methods

after_response(&block) click to toggle source
    # File lib/sinatra/base.rb
245 def after_response(&block)
246   raise NotImplementedError, 'only supports EventMachine at the moment' unless defined? EventMachine
247 
248   EventMachine.next_tick(&block)
249 end
async?(status, _headers, body) click to toggle source
    # File lib/sinatra/base.rb
251 def async?(status, _headers, body)
252   return true if status == -1
253 
254   body.respond_to?(:callback) && body.respond_to?(:errback)
255 end
setup_close(env, _status, _headers, body) click to toggle source
    # File lib/sinatra/base.rb
238 def setup_close(env, _status, _headers, body)
239   return unless body.respond_to?(:close) && env.include?('async.close')
240 
241   env['async.close'].callback { body.close }
242   env['async.close'].errback { body.close }
243 end