Ruby、Sinatra 和关闭连接
有谁知道是否有办法阻止 Sinatra 在其响应中发送“连接:关闭”标头?
需要明确的是,我有一个非常简单的
get '/path' do
puts "Some (~200 byte long) string"
end
但是,在查看网络分析器中的输出后,我发现它在 HTTP/1.1 200 OK
之后发送 Connection: close
标头code>,我想停止!
Does anyone know if there is a way to prevent Sinatra from sending the 'Connection: close' header in its responses?
To be clear, I have a very simple
get '/path' do
puts "Some (~200 byte long) string"
end
But, after looking at the output in a network analyser, I see it's sending the Connection: close
header right after the HTTP/1.1 200 OK
, which I'd like to stop!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊哈!我的 Sinatra 应用程序运行所在的服务器 Mongrel 似乎不支持 Keep-Alive。所以我就这么做了:
在
gem install Thin
之后,一切似乎都工作得更好了!Ah ha! It seems Mongrel, the server my Sinatra app was running on, doesn't support Keep-Alive. so I just did:
after
gem install thin
and everything seems to be working better!我根本不会说 Ruby,Sinatra 网站也不太清楚它是什么(它是 Ruby 的框架吗?),所以我可能完全疯了,但是:
Connection: close< /code> 当保持活动关闭时由您的 Web 服务器发送。出于可扩展性的原因,保持活动通常被认为是服务器中要关闭的操作的第一步。公平地说,有一个双向的思想流派,特别是当涉及到 Ajax 时。
我在 Django 工作中使用 nginx(我认为它是相似的),并且我在 nginx 中关闭了 keep-alives,如下所示:
Apache 使用 KeepAlive(请参阅 此处)。
如果 Sinatra 是它自己的 Web 服务器,我找不到任何文档来打开 keep-alives,我会继续接受我看起来像个白痴的事实。
I don't speak Ruby at all, and the Sinatra site isn't terribly clear on what it is (is it a framework for Ruby?) so I might be completely off my rocker here, but:
Connection: close
is sent by your Web server when keep alives are turned off. For scalability reasons, keep alives are generally considered to be step one on things to turn off in your server. To be fair, there's a school of thought both ways, particularly when Ajax is involved.I use nginx for my Django work (I'm thinking it's similar), and I have keep-alives turned off in nginx like this:
Apache uses KeepAlive (see here).
If Sinatra is its own Web server, I can't find any documentation to turn keep alives on, and I'll go ahead and eat the fact that I look like an idiot.