Project

General

Profile

Actions

Bug #7469

closed

WEBrick "Could not determine content-length of response body. Set content-length of the response..." even when content-length is set

Added by meta (mathew murphy) over 11 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
Backport:
[ruby-core:50340]

Description

Minimal demonstration code:

########
require 'webrick'

class BugDemonstrator < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
response.body = ''
response.status = 204
response.content_length = 0
end
end

server = WEBrick::HTTPServer.new(:Port => 8080, :AccessLog => [])
server.mount "/", BugDemonstrator
trap("INT") do
server.shutdown
end
server.start
########

Output when run, connecting to localhost:8080 to issue an HTTP GET:

$ ruby webrickbug.rb
[2012-11-29 13:21:25] INFO WEBrick 1.3.1
[2012-11-29 13:21:25] INFO ruby 1.9.3 (2012-11-10) [x86_64-linux]
[2012-11-29 13:21:25] WARN TCPServer Error: Address already in use - bind(2)
[2012-11-29 13:21:25] INFO WEBrick::HTTPServer#start: pid=4941 port=8080
[2012-11-29 13:21:29] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
^C[2012-11-29 13:21:32] INFO going to shutdown ...
[2012-11-29 13:21:32] INFO WEBrick::HTTPServer#start done.
$ ruby --version
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
$

I'm doing literally what the warning message says to do -- i.e. setting the content-length of the response -- but I'm still getting the warning.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0