ruby-changes:20140
From: nahi <ko1@a...>
Date: Tue, 21 Jun 2011 22:01:17 +0900 (JST)
Subject: [ruby-changes:20140] nahi:r32188 (trunk): * lib/webrick/httpresponse.rb (HTTPResponse#setup_header): Close
nahi 2011-06-21 21:58:37 +0900 (Tue, 21 Jun 2011) New Revision: 32188 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32188 Log: * lib/webrick/httpresponse.rb (HTTPResponse#setup_header): Close HTTP/1.1 connection when returning an IO object as response body without setting HTTPResponse#chunked to true. See #855 no.1. * test/webrick/test_httpserver.rb: Test it. Modified files: trunk/ChangeLog trunk/lib/webrick/httpresponse.rb trunk/test/webrick/test_httpserver.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32187) +++ ChangeLog (revision 32188) @@ -1,3 +1,11 @@ +Tue Jun 21 21:50:37 2011 Hiroshi Nakamura <nahi@r...> + + * lib/webrick/httpresponse.rb (HTTPResponse#setup_header): Close + HTTP/1.1 connection when returning an IO object as response body + without setting HTTPResponse#chunked to true. See #855 no.1. + + * test/webrick/test_httpserver.rb: Test it. + Tue Jun 21 21:27:34 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * internal.h: move rb_thread_io_blocking_region() declaration Index: lib/webrick/httpresponse.rb =================================================================== --- lib/webrick/httpresponse.rb (revision 32187) +++ lib/webrick/httpresponse.rb (revision 32188) @@ -204,6 +204,11 @@ elsif keep_alive? if chunked? || @header['content-length'] @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 @header['connection'] = "close" Index: test/webrick/test_httpserver.rb =================================================================== --- test/webrick/test_httpserver.rb (revision 32187) +++ test/webrick/test_httpserver.rb (revision 32188) @@ -258,6 +258,33 @@ assert_equal(stopped, 1) end + def test_response_io_without_chunked_set + config = { + :ServerName => "localhost" + } + TestWEBrick.start_httpserver(config){|server, addr, port, log| + server.mount_proc("/", lambda { |req, res| + r,w = IO.pipe + # Test for not setting chunked... + # res.chunked = true + res.body = r + w << "foo" + w.close + }) + Thread.pass while server.status != :Running + http = Net::HTTP.new(addr, port) + req = Net::HTTP::Get.new("/") + req['Connection'] = 'Keep-Alive' + begin + timeout(2) do + http.request(req){|res| assert_equal("foo", res.body) } + end + rescue Timeout::Error + flunk('corrupted reponse') + end + } + end + def test_request_handler_callback_is_deprecated requested = 0 config = { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/