Sinatra :: Streaming with Rack not chunking response

I have a hard time trying to get this simple stream test to work using Sinatra and Rack.

In my stream.rb file, I have:

require 'sinatra'
require 'sinatra/streaming'
class StreamAPI < Sinatra::Base
    helpers Sinatra::Streaming
    get '/stream' do
        stream do |out|
            5.times do
                out.puts "Hello!"
                sleep 1
            end
            out.flush
        end
    end
    run! if app_file == $0
end

And in my config.ru I have:

require 'rack'
require './stream.rb'
run StreamAPI

When I twist the URL, I get "Hello!". 5 times, but all right after 5 seconds. Looking at the headlines, I see that it is Transfer-Encodingset to Chunked. I want "Hello!" to go through another after a pause of 1 second.


Edit: In addition to the selected answer below I also need to add proxy_buffering off;to my config file NGINX.

+4
source share
1 answer

, . Sinatra README:

, , , -, . , WEBRick, . , , , , .

, , . (, Thin Puma), .

+3

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


All Articles