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

前端 未结 9 2660
离开以前
离开以前 2020-11-27 09:35

Since upgrading to Rails 3.1 I\'m seeing this warning message in my development log:

WARN Could not determine content-length of response body. Set co

相关标签:
9条回答
  • 2020-11-27 09:43

    Another workaround that removes the offending line from webrick. It's just not that useful:

    cd `which ruby`/../../lib/ruby/1.9.1/webrick/ && sed -i '.bak' -e'/logger.warn/d' httpresponse.rb
    

    (you may need to sudo)

    0 讨论(0)
  • 2020-11-27 09:46

    This problem has been fixed in Ruby's trunk branch with this commit to webrick.

    You can edit this particular webrick file similarly in your setup. The approximate location can be found by:

    gem which webrick
    

    To actually edit the file:

    nano \`ruby -e"print %x{gem which webrick}.chomp %Q{.rb\n}"\`/httpresponse.rb
    

    (Or instead of nano, use your favorite editor.)

    0 讨论(0)
  • 2020-11-27 09:47

    JRuby version: If you're using .rvm, do this to fix it...

    As mentioned by João Soares and Kjellski, this is what you can do if you want to get rid of this warning on development and you are using JRuby.

    1. Use your favorite editor to open this file:

      ~/.rvm/rubies/jruby-<version>/lib/ruby/<1.8 or 1.9>/webrick/httpresponse.rb
      
    2. Go to the line that contains this (for me it was line 205):

      if chunked? || @header['content-length']
      
    3. Change it, taken from this patch, to this:

      if chunked? || @header['content-length'] || @status == 304 || @status == 204
      
    4. Save the file and eventually restart your rails server.

    0 讨论(0)
  • 2020-11-27 09:57

    Just explicitly adding the Gem to the Gemfile got rid of the warning messages for me:

    group :development do
      gem 'webrick', '~> 1.3.1'
    end
    
    0 讨论(0)
  • 2020-11-27 09:57

    If you're using .rvm, do this to fix it...

    As mentioned by João Soares, all credits to him, this is what you can do if you wan't to get rid of this warning on development.

    1. Use your favorite editor to open this file:

      ~/.rvm/rubies/<ruby-version>/lib/ruby/1.9.1/webrick/httpresponse.rb
      
    2. Go to the line that contains this(for me it was really line 206):

      if chunked? || @header['content-length']
      
    3. Change it, taken from this patch, to this:

      if chunked? || @header['content-length'] || @status == 304 || @status == 204
      
    4. Save the file and eventually restart your rails server

    0 讨论(0)
  • 2020-11-27 10:04

    Add

    config.middleware.use Rack::ContentLength
    

    to your application.rb file, and the warning will disappear even with webrick. This will also set Content-Length properly in production when rendering a json or text response.

    0 讨论(0)
提交回复
热议问题