Ruby1.9.3のWebrickで出るCould not determine content-length...エラーを消す方法(2.0.0では解決済)

Tags: [ Ruby ] [ Rails ] Published: 2013/09/03



      [yyyy-mm-dd ...] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


  • Ruby 1.9.3
  • Redmine 2.3.1
    • Rails 3.2.13
    • WEBrick 1.3.1



以下のパッチをあてる or 該当ファイルを変更する。


2.0.0 ではなおってた!

          # Keep-Alive connection.
      if @header['connection'] == "close"
        @keep_alive = false
      elsif keep_alive?
        if chunked? || @header['content-length'] || @status == 304 || @status == 204 ||
          @header['connection'] = "Keep-Alive"

ちなみに、 Railsのissue を見ると、みんな発生してた様子。


So if you want to do keep-alive, even if you add a content length, you will always get a warning. RFC2616 Section 4.4 says:

1.Any response message which “MUST NOT” include a message-body (such as the 1xx, 204, and 304 responses and any response to a HEAD request) is always terminated by the first empty line after the header fields, regardless of the entity-header fields present in the message

I think this means that clients will know the length of the body, and clients can support keep-alive connections with no content-length for these types of responses.

Author: kk_Ataka / Powered by Jekyll on GitHub Pages