summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-21 12:58:37 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-21 12:58:37 +0000
commit4ce158147502304af431c820c227134628578e74 (patch)
tree27d8a9235f3673c2bd9a7c47d9e1a29494b015e4
parent908baefe7da367539092994fdbc718a43772e956 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--lib/webrick/httpresponse.rb5
-rw-r--r--test/webrick/test_httpserver.rb27
3 files changed, 40 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 5bdf7bec59..fa5e2c2b6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Jun 21 21:50:37 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
+
+ * 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@gmail.com>
* internal.h: move rb_thread_io_blocking_region() declaration
diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb
index b7c61a2b2f..0d36c0747e 100644
--- a/lib/webrick/httpresponse.rb
+++ b/lib/webrick/httpresponse.rb
@@ -204,6 +204,11 @@ module WEBrick
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"
diff --git a/test/webrick/test_httpserver.rb b/test/webrick/test_httpserver.rb
index b4bdd84045..526d72c381 100644
--- a/test/webrick/test_httpserver.rb
+++ b/test/webrick/test_httpserver.rb
@@ -258,6 +258,33 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
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 = {