lib/action_controller/metal/streaming.rb in actionpack-3.2.22.5 vs lib/action_controller/metal/streaming.rb in actionpack-4.0.0.beta1

- old
+ new

@@ -1,6 +1,5 @@ -require 'active_support/core_ext/file/path' require 'rack/chunked' module ActionController #:nodoc: # Allows views to be streamed back to the client as they are rendered. # @@ -20,19 +19,17 @@ # # In order to use streaming, you will need to use a Ruby version that # supports fibers (fibers are supported since version 1.9.2 of the main # Ruby implementation). # - # == Examples - # # Streaming can be added to a given template easily, all you need to do is # to pass the :stream option. # # class PostsController # def index - # @posts = Post.scoped - # render :stream => true + # @posts = Post.all + # render stream: true # end # end # # == When to use streaming # @@ -52,14 +49,14 @@ # Most of the queries here are happening in the controller. In order to benefit # from streaming you would want to rewrite it as: # # def dashboard # # Allow lazy execution of the queries - # @posts = Post.scoped - # @pages = Page.scoped - # @articles = Article.scoped - # render :stream => true + # @posts = Post.all + # @pages = Page.all + # @articles = Article.all + # render stream: true # end # # Notice that :stream only works with templates. Rendering :json # or :xml with :stream won't work. # @@ -138,21 +135,18 @@ # When streaming, the HTTP headers are sent to the client right before # it renders the first line. This means that, modifying headers, cookies, # session or flash after the template starts rendering will not propagate # to the client. # - # If you try to modify cookies, session or flash, an +ActionDispatch::ClosedError+ - # will be raised, showing those objects are closed for modification. - # # == Middlewares # # Middlewares that need to manipulate the body won't work with streaming. # You should disable those middlewares whenever streaming in development - # or production. For instance, +Rack::Bug+ won't work when streaming as it + # or production. For instance, <tt>Rack::Bug</tt> won't work when streaming as it # needs to inject contents in the HTML body. # - # Also +Rack::Cache+ won't work with streaming as it does not support + # Also <tt>Rack::Cache</tt> won't work with streaming as it does not support # streaming bodies yet. Whenever streaming Cache-Control is automatically # set to "no-cache". # # == Errors # @@ -161,11 +155,11 @@ # the client, making it impossible to render a whole exception page. # # Currently, when an exception happens in development or production, Rails # will automatically stream to the client: # - # "><script type="text/javascript">window.location = "/500.html"</script></html> + # "><script>window.location = "/500.html"</script></html> # # The first two characters (">) are required in case the exception happens # while rendering attributes for a given tag. You can check the real cause # for the exception in your logger. # @@ -178,11 +172,11 @@ # # Unicorn supports streaming but it needs to be configured. For this, you # need to create a config file as follow: # # # unicorn.config.rb - # listen 3000, :tcp_nopush => false + # listen 3000, tcp_nopush: false # # And use it on initialization: # # unicorn_rails --config-file unicorn.config.rb # @@ -193,11 +187,11 @@ # Streaming should work out of the box on Rainbows. # # ==== Passenger # # To be described. - # + # module Streaming extend ActiveSupport::Concern include AbstractController::Rendering @@ -215,10 +209,10 @@ headers.delete("Content-Length") end end end - # Call render_to_body if we are streaming instead of usual +render+. + # 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