Module: LongBody::ThinHandler

Extended by:
ThinHandler
Included in:
ThinHandler
Defined in:
lib/long_body/thin_handler.rb

Overview

Turns an iterable Rack response body that responds to each() into something that Thin can use within EventMachine. Uses internal Thin interfaces so not applicable for other servers.

Defined Under Namespace

Classes: BodyWrapperWithExplicitClose, FiberWrapper, ResponseSender

Constant Summary collapse

AsyncResponse =
[-1, {}, []].freeze
C_async_close =
'async.close'.freeze
C_async_callback =
'async.callback'.freeze

Instance Method Summary collapse

Instance Method Details

#perform(env, s, h, b) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/long_body/thin_handler.rb', line 92

def perform(env, s, h, b)
  # Wrap in a handler that will raise from within each() 
  # if async.close is triggered while the response is dripping by
  b = BodyWrapperWithExplicitClose.new(b)
  
  # Wrap in a handler that manages the DeferrableBody
  sender = ResponseSender.new(b)
  
  # Abort the body sending on both of those.
  env[C_async_close].callback { sender.abort! }
  env[C_async_close].errback { sender.abort! }
  env[C_async_callback].call([s, h, sender.deferrable_body])
  sender.send_next_chunk
  
  AsyncResponse # Let Thin know we are using async.*
end