【问题标题】:WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [duplicate]WARN 无法确定响应正文的内容长度。设置响应的内容长度或设置 Response#chunked = true [重复]
【发布时间】:2012-03-25 15:19:20
【问题描述】:

可能重复:
What does “WARN Could not determine content-length of response body.” mean and how to I get rid of it?

我刚刚升级到 rails 3.2.2,现在在 rails 上,页面加载,我在日志中得到了所有这些错误:

[2012-03-07 19:46:14] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2012-03-07 19:46:14] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

根据之前的 SO 线程,我尝试了以下方法:

/config/application.rb

config.assets.logger = false
config.assets.logger = nil

这些都不起作用。关于如何为此错误禁用此日志记录的任何想法?或者解决问题:)

谢谢

【问题讨论】:

  • 虽然它可能是重复的,但它确实需要引起 Rails 团队的注意,因为它已经超过 6 个月了,并且一个新版本,因为他们承认他们需要清理它,但他们仍然没有.

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

这是 Webrick 的问题。 你可以改用“瘦”。

将此添加到 Gemfile

gem 'thin'

然后rails s 将使用thin 而不是Webrick,警告将消失。

【讨论】:

  • 在你的 config/environmenst/development.rb 中,添加这一行:config.middleware.use Rails::Rack::LogTailer
  • @cam song: 几乎正确:rails s thin 将使用 Thin 而不是 Webrick,并且警告会消失。
  • 我第二次使用 Thin 而不是 WEBrick。然而。在 Windows 上,瘦依赖项(更具体地说是 eventmachine)的安装可能会出现问题。我在我的 Gemfile 中使用以下内容来全新安装 Thin:gem 'eventmachine', '1.0.0.rc.4', :platforms => [:mswin, :mingw]注意:我通过RailsInstaller 安装了Rails,其中包括DevKit。没有它可能无法工作(?)。
  • 在 Rails 3.2 及更高版本上 rails s 如果 Gemfile 中存在 Thin 将使用它。
  • 不起作用。 puma 工作
【解决方案2】:

Amiel Martin 提到的补丁对我有用!只需找到您的 webrick 路径(例如,Windows 上的 c:\Ruby\lib\ruby\1.9.1\webrick\)并按照中所述更改 httpresponse.rb 文件https://bugs.ruby-lang.org/attachments/2300/204_304_keep_alive.patch

别忘了重启 Webrick!

【讨论】:

  • 我明确地将 WEBrick 1.3.1 版添加到我的 gemfile 中,这解决了问题。
  • 奇怪:根据我运行 rails s 时显示的消息,我已经在使用 WEBrick 1.3.1(与 Rails 3.2.8),但我仍然收到警告消息。我将gem 'webrick', '1.3.1' 添加到我的gemfile 中并且警告停止了。 1.3.1 的不同版本?
  • 这并没有为我解决,可能是因为我使用的是 RVM。不确定在哪里使用 RVM 进行此更改。但是将 gem 'webrick', '1.3.1' 放入我的 Gemfile 和 bundle install 并重新启动服务器对我有用并删除了消息。
【解决方案3】:

据报道,这个 WEBrick 补丁也可以工作:

https://bugs.ruby-lang.org/attachments/2300/204_304_keep_alive.patch

【讨论】:

    猜你喜欢
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 2012-09-29
    • 2016-03-17
    • 1970-01-01
    • 2015-04-30
    相关资源
    最近更新 更多