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 = env[HTTP_VERSION] == HTTP11 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 headers[TRANSFER_ENCODING] = CHUNKED throw :halt, res.finish_with_body(Body.new(self)) end