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

AnA*_*ice 119 ruby-on-rails ruby-on-rails-3

可能重复:
"WARN无法确定响应体的内容长度."是什么意思以及如何摆脱它?

我刚刚升级到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
Run Code Online (Sandbox Code Playgroud)

根据以前的SO线程,我尝试了以下内容:

/config/application.rb

config.assets.logger = false
config.assets.logger = nil
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Cam*_*ong 165

这是Webrick的问题.你可以使用"Thin"代替.

将其添加到Gemfile

gem 'thin'
Run Code Online (Sandbox Code Playgroud)

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

  • @cam歌曲:几乎正确:`rails s thin`将使用thin而不是Webrick,并且警告将消失. (7认同)
  • 在Rails 3.2及以上版本中,如果在Gemfile中存在,则rails s`将使用thin. (7认同)
  • 我第二次使用thin而不是WEBrick.然而.在Windows上,瘦依赖项(更具体地说是事件机器)的安装可能会有问题.我在我的Gemfile中使用以下内容来彻底安装thin:`gem'eventmachine','1.0.0.rc.4',: platforms => [:mswin,:mingw]`.**注意**:我通过[RailsInstaller](http://railsinstaller.org/)安装了Rails,其中包括[DevKit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit).没有它可能无法工作(?). (2认同)

Ant*_*ony 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!

  • 我明确地将WEBrick的1.3.1版本添加到我的gemfile中,这解决了这个问题. (42认同)
  • 奇怪:根据我运行`rails s`时显示的消息,我已经在使用WEBrick 1.3.1(使用Rails 3.2.8),但我仍然收到警告消息.我将'gem'webrick','1.3.1'添加到我的gemfile中,警告停止了.1.3.1的不同版本? (10认同)
  • 这并没有为我解决,也许是因为我正在使用RVM.不确定在哪里使用RVM进行此更改.然而,在我的Gemfile和`bundle install`中放置'gem'webrick','1.3.1'`并重新启动服务器为我工作并删除了消息. (6认同)