Skip to content

Instantly share code, notes, and snippets.

@willnet
Created October 21, 2013 13:20
Show Gist options
  • Save willnet/7083780 to your computer and use it in GitHub Desktop.
Save willnet/7083780 to your computer and use it in GitHub Desktop.
module ActionController
module Streaming
extend ActiveSupport::Concern
protected
# Set proper cache control and transfer encoding when streaming
def _process_options(options) #:nodoc:
super
if options[:stream]
if env["HTTP_VERSION"] == "HTTP/1.0"
options.delete(:stream)
else
headers["Cache-Control"] ||= "no-cache"
headers["Transfer-Encoding"] = "chunked"
headers.delete("Content-Length")
end
end
end
# Call render_body if we are streaming instead of usual +render+.
def _render_template(options) #:nodoc:
if options.delete(:stream)
Rack::Chunked::Body.new view_renderer.render_body(view_context, options)
else
super
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment