module Roda::RodaPlugins::Chunked::InstanceMethods
def chunked(template, opts=OPTS, &block)
Render a response to the user in chunks. See Chunked for
def chunked(template, opts=OPTS, &block) unless defined?(@_chunked) @_chunked = !self.opts[:force_chunked_encoding] || @_request.http_version == "HTTP/1.1" end if block delay(&block) end unless @_chunked # If chunking is disabled, do a normal rendering of the view. run_delayed_blocks return view(template, opts) end if template.is_a?(Hash) if opts.empty? opts = template else opts = Hash[opts].merge!(template) end end # Hack so that the arguments don't need to be passed # through the response and body objects. @_each_chunk_args = [template, opts] res = response headers = res.headers if chunk_headers = self.opts[:chunk_headers] headers.merge!(chunk_headers) end if self.opts[:force_chunked_encoding] res[RodaResponseHeaders::TRANSFER_ENCODING] = 'chunked' body = Body.new(self) else body = StreamBody.new(self) end throw :halt, res.finish_with_body(body) end