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