From 5097d2cf7359193b16fa31395efe69532a59b1d6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Mar 2009 13:06:54 -0700 Subject: test_response: ensure closed socket after write We always close the socket immediately after a successful write for two reasons: 1) To prevent error responses from being rewritten. If we throw an exception in our request/app/response chain, we'll attempt to write an HTTP 400/500 response out if the socket is open. No way to write to an open socket. 2) To uncork the socket if TCP_CORK is enabled (Linux) ASAP. This should be a tick faster than waiting to go back up the stack and close it there. --- test/unit/test_response.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test') diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index 62cabdf..17732fe 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -13,6 +13,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_headers out = StringIO.new HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) + assert out.closed? assert out.length > 0, "output didn't have data" end @@ -22,6 +23,7 @@ class ResponseTest < Test::Unit::TestCase $, = "\f\v" out = StringIO.new HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) + assert out.closed? resp = out.string assert ! resp.include?("\f\v"), "output didn't use $, ($OFS)" ensure @@ -31,6 +33,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_200 io = StringIO.new HttpResponse.write(io, [200, {}, []]) + assert io.closed? assert io.length > 0, "output didn't have data" end @@ -38,6 +41,7 @@ class ResponseTest < Test::Unit::TestCase code = 400 io = StringIO.new HttpResponse.write(io, [code, {}, []]) + assert io.closed? lines = io.string.split(/\r\n/) assert_match(/.* #{HTTP_STATUS_CODES[code]}$/, lines.first, "wrong default reason phrase") @@ -46,6 +50,7 @@ class ResponseTest < Test::Unit::TestCase def test_rack_multivalue_headers out = StringIO.new HttpResponse.write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []]) + assert out.closed? assert_match(/^X-Whatever: stuff\r\nX-Whatever: bleh\r\n/, out.string) end -- cgit v1.2.3-24-ge0c7