diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-29 13:06:54 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-29 13:06:54 -0700 |
commit | 5097d2cf7359193b16fa31395efe69532a59b1d6 (patch) | |
tree | 5a75523b275192a73655d6a18dcfd7da1cb9d12b | |
parent | c83b5a903a076fda67c7d062da1ad6ff9337fdd1 (diff) | |
download | unicorn-5097d2cf7359193b16fa31395efe69532a59b1d6.tar.gz |
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.
-rw-r--r-- | test/unit/test_response.rb | 5 |
1 files changed, 5 insertions, 0 deletions
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 |