123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::ExtendedRack

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: lib/sinatra/base.rb

Overview

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.

Instance Attribute Summary

  • #app rw

    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.

Instance Method Summary

Instance Attribute Details

#app (rw)

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.

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 222

class ExtendedRack < Struct.new(:app)

Instance Method Details

#after_response(&block) (private)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 242

def after_response(&block)
  raise NotImplementedError, 'only supports EventMachine at the moment' unless defined? EventMachine

  EventMachine.next_tick(&block)
end

#async?(status, _headers, body) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 248

def async?(status, _headers, body)
  return true if status == -1

  body.respond_to?(:callback) && body.respond_to?(:errback)
end

#call(env)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 223

def call(env)
  result = app.call(env)
  callback = env['async.callback']
  return result unless callback && async?(*result)

  after_response { callback.call result }
  setup_close(env, *result)
  throw :async
end

#setup_close(env, _status, _headers, body) (private)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 235

def setup_close(env, _status, _headers, body)
  return unless body.respond_to?(:close) && env.include?('async.close')

  env['async.close'].callback { body.close }
  env['async.close'].errback { body.close }
end