在我的stream.rb文件中,我有:
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 ==require 'rack'require './stream.rb'run StreamAPIend
在我的config.ru我有:
当我卷曲网址时,我得到“你好!” 5次,但5秒后一次全部.查看标题我可以看到transfer-encoding设置为Chunked.我想要的是“你好!”在暂停1秒之后再通过另一个.
编辑:除了下面选择的答案,我还需要关闭proxy_buffering;到我的Nginx配置文件.
解决方法 这取决于您使用的服务器.从 Sinatra README:Note that the streaming behavior,especially the number of concurrent requests,highly depends on the web server used to serve the application. Some servers,like WEBRick,might not even support streaming at all. If the server does not support streaming,the body will be sent all at once after the block passed to stream finishes executing.
看起来您正在使用不支持流式传输的服务器.如果你切换到一个(例如Thin或Puma)这应该工作.
总结以上是内存溢出为你收集整理的ruby – Sinatra :: Streaming with Rack没有分块响应全部内容,希望文章能够帮你解决ruby – Sinatra :: Streaming with Rack没有分块响应所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)