diff --git a/ChangeLog b/ChangeLog index 7177b49978..f7612551d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Dec 13 07:13:28 2011 Aaron Patterson + + * lib/webrick/httpresponse.rb (setup_header): 204 and 304 responses + are allowed to have a Keep-Alive connection. [ruby-core:41581] + + * test/webrick/test_httpresponse.rb: corresponding test. + Tue Dec 13 06:29:39 2011 Nobuyoshi Nakada * parse.y (parser_magic_comment): should pass the proper value. diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index 0d36c0747e..ce72b3f9d6 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -202,7 +202,7 @@ module WEBrick if @header['connection'] == "close" @keep_alive = false elsif keep_alive? - if chunked? || @header['content-length'] + 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" diff --git a/test/webrick/test_httpresponse.rb b/test/webrick/test_httpresponse.rb new file mode 100644 index 0000000000..3967e2c3e8 --- /dev/null +++ b/test/webrick/test_httpresponse.rb @@ -0,0 +1,46 @@ +require "webrick" +require "minitest/autorun" + +module WEBrick + class TestHTTPResponse < MiniTest::Unit::TestCase + class FakeLogger + attr_reader :messages + + def initialize + @messages = [] + end + + def warn msg + @messages << msg + end + end + + def test_304_does_not_log_warning + logger = FakeLogger.new + config = Config::HTTP + config[:Logger] = logger + + res = HTTPResponse.new config + res.status = 304 + res.keep_alive = true + + res.setup_header + + assert_equal 0, logger.messages.length + end + + def test_204_does_not_log_warning + logger = FakeLogger.new + config = Config::HTTP + config[:Logger] = logger + + res = HTTPResponse.new config + res.status = 204 + res.keep_alive = true + + res.setup_header + + assert_equal 0, logger.messages.length + end + end +end