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 217 def call(env) 218 result, callback = app.call(env), env['async.callback'] 219 return result unless callback and async?(*result) 220 after_response { callback.call result } 221 setup_close(env, *result) 222 throw :async 223 end
Private Instance Methods
after_response(&block)
click to toggle source
# File lib/sinatra/base.rb 233 def after_response(&block) 234 raise NotImplementedError, "only supports EventMachine at the moment" unless defined? EventMachine 235 EventMachine.next_tick(&block) 236 end
async?(status, headers, body)
click to toggle source
# File lib/sinatra/base.rb 238 def async?(status, headers, body) 239 return true if status == -1 240 body.respond_to? :callback and body.respond_to? :errback 241 end
setup_close(env, status, headers, body)
click to toggle source
# File lib/sinatra/base.rb 227 def setup_close(env, status, headers, body) 228 return unless body.respond_to? :close and env.include? 'async.close' 229 env['async.close'].callback { body.close } 230 env['async.close'].errback { body.close } 231 end