proc" in 2.2.2 and 2.3.2 I am experiencing something that I cannot explain with Rails 2.3.2. I created a new application...">

Rails "render: text => proc" in 2.2.2 and 2.3.2

I am experiencing something that I cannot explain with Rails 2.3.2. I created a new application with one controller and one action to narrow it down. My entire controller is as follows.

class LinesController < ApplicationController
  def show
    respond_to do |format|
      format.html { render :text => proc {|response, output|
          10.times do |i|
            output.write("This is line #{i}\n")
            output.flush
          end
        }
      }
    end
  end
end

When I run this under Rails 2.2.2, I see the following answer.

$ curl http://localhost:3002/lines
This is line 0
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
This is line 8
This is line 9

However, when I run it under Rails 2.3.2, I get this instead.

$ curl http://localhost:3002/lines
curl: (18) transfer closed with outstanding read data remaining

If I hit this with a browser, I only see the first line.

This is line 0

Please note that my sample code is directly from the Rails documentation for render , except that I have reduced the number of lines from 10 million to 10.

I suspect the answer lies somewhere in the flush () method, but I'm currently stuck trying to dig up the explanation from the source code.

+3
1

, 2-3- bc2c4a45959be21e6314fba7876b32c1f04cd08a. . 2.3.3 ( ), 2-3- git:

git clone git://github.com/rails/rails.git vendor/rails
cd vendor/rails
git checkout origin/2-3-stable
rm -rf .git
+3

Source: https://habr.com/ru/post/1712147/


All Articles