Created
October 21, 2013 13:20
-
-
Save willnet/7083780 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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