Class: Strobe::Middleware::Proxy::ProxyRequest::DeferrableBody

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/strobe/middleware/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ DeferrableBody

Returns a new instance of DeferrableBody.



139
140
141
# File 'lib/strobe/middleware/proxy.rb', line 139

def initialize(request)
  @request = request
end

Instance Method Details

#call(body) ⇒ Object



143
144
145
146
147
148
# File 'lib/strobe/middleware/proxy.rb', line 143

def call(body)
  Array(body).each do |chunk|
    chunk = prepare_chunk(chunk)
    @callback.call(chunk)
  end
end

#each(&blk) ⇒ Object



160
161
162
# File 'lib/strobe/middleware/proxy.rb', line 160

def each(&blk)
  @callback = blk
end

#prepare_chunk(chunk) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/strobe/middleware/proxy.rb', line 150

def prepare_chunk(chunk)
  if @request.chunked_response_body?
    size = chunk.respond_to?(:bytesize) ? chunk.bytesize : chunk.length
    "#{size.to_s(16)}\r\n#{chunk}\r\n"
  else
    # Thin doesn't like null bodies
    chunk || ''
  end
end