Class: Sinatra::ExtendedRack
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Struct
|
|
Instance Chain:
self,
Struct
|
|
Inherits: |
Struct
|
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.
# File 'lib/sinatra/base.rb', line 225
class ExtendedRack < Struct.new(:app)
Instance Method Details
#after_response(&block) (private)
# File 'lib/sinatra/base.rb', line 245
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)
# File 'lib/sinatra/base.rb', line 251
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 226
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 238
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