WARN Could not determine content-length of response body

环境

ruby 1.9.3p0

rails  3.2.6

 

启动WEBrick服务器的时候,会有如下警告:

 

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

 

解决办法:

找到ruby的安装路径:

D:\Ruby193\lib\ruby\1.9.1\webrick\httpresponse.rb

 

 if @header['connection'] == "close"
         @keep_alive = false
      elsif keep_alive?
        if chunked? || @header['content-length'] || @status == 304 || @status == 204
 
          @header['connection'] = "Keep-Alive"
        else
          msg = "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"
          @logger.warn(msg)
          @header['connection'] = "close"
          @keep_alive = false
        end
      else

 

原程序:

 

if chunked? || @header['content-length'] 

修改为:

 

 if chunked? || @header['content-length'] || @status == 304 || @status == 204
 重新启动WEBrick,警告就没哟了

 

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

 

你可能感兴趣的:(Content-Length,response body)