Ruby、Sinatra 和关闭连接

发布于 2024-08-11 05:41:11 字数 265 浏览 4 评论 0原文

有谁知道是否有办法阻止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悟红尘 2024-08-18 05:41:11

啊哈!我的 Sinatra 应用程序运行所在的服务器 Mongrel 似乎不支持 Keep-Alive。所以我就这么做了:

set :server, 'thin'

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:

set :server, 'thin'

after gem install thin and everything seems to be working better!

策马西风 2024-08-18 05:41:11

我根本不会说 Ruby,Sinatra 网站也不太清楚它是什么(它是 Ruby 的框架吗?),所以我可能完全疯了,但是:

Connection: close< /code> 当保持活动关闭时由您的 Web 服务器发送。出于可扩展性的原因,保持活动通常被认为是服务器中要关闭的操作的第一步。公平地说,有一个双向的思想流派,特别是当涉及到 Ajax 时。

我在 Django 工作中使用 nginx(我认为它是相似的),并且我在 nginx 中关闭了 keep-alives,如下所示:

14:58 jsmith@lateralus% grep alive /etc/nginx/nginx.conf                            ~
     keepalive_timeout 0;

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:

14:58 jsmith@lateralus% grep alive /etc/nginx/nginx.conf                            ~
     keepalive_timeout 0;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文