警告无法确定响应正文的内容长度。设置响应的内容长度或设置Response#chunked = true

时间:2012-03-08 03:49:58

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

  

可能重复:
  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 s上,页面加载,我在日志中得到所有这些错误:

[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

这些都没有奏效。有关如何针对此错误禁用此日志记录的任何想法?或者解决问题:)

由于

3 个答案:

答案 0 :(得分:165)

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

将其添加到Gemfile

gem 'thin'

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

答案 1 :(得分:28)

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!

答案 2 :(得分:9)

据报道,这个针对WEBrick的补丁也有效:

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