From 50c11036dd4898ccfed8b3e0552e88c67b6c63a9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 27 Aug 2010 20:29:55 +0000 Subject: http_response: avoid singleton method There's no need for a response class or object since Rack just uses an array as the response. So use a procedural style which allows for easier understanding. We shall also support keepalive/pipelining in the future, too. --- test/unit/test_response.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index f9eda8e..e5245e8 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -11,10 +11,11 @@ require 'test/test_helper' include Unicorn class ResponseTest < Test::Unit::TestCase - + include Unicorn::HttpResponse + def test_response_headers out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) + http_response_write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) assert out.closed? assert out.length > 0, "output didn't have data" @@ -22,7 +23,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_string_status out = StringIO.new - HttpResponse.write(out,['200', {}, []]) + http_response_write(out,['200', {}, []]) assert out.closed? assert out.length > 0, "output didn't have data" assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/).size @@ -32,7 +33,7 @@ class ResponseTest < Test::Unit::TestCase old_ofs = $, $, = "\f\v" out = StringIO.new - HttpResponse.write(out,[200, {"X-k" => "cd","X-y" => "z"}, ["cool"]]) + http_response_write(out,[200, {"X-k" => "cd","X-y" => "z"}, ["cool"]]) assert out.closed? resp = out.string assert ! resp.include?("\f\v"), "output didn't use $, ($OFS)" @@ -42,7 +43,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_200 io = StringIO.new - HttpResponse.write(io, [200, {}, []]) + http_response_write(io, [200, {}, []]) assert io.closed? assert io.length > 0, "output didn't have data" end @@ -50,7 +51,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_with_default_reason code = 400 io = StringIO.new - HttpResponse.write(io, [code, {}, []]) + http_response_write(io, [code, {}, []]) assert io.closed? lines = io.string.split(/\r\n/) assert_match(/.* Bad Request$/, lines.first, @@ -59,7 +60,7 @@ class ResponseTest < Test::Unit::TestCase def test_rack_multivalue_headers out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []]) + http_response_write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []]) assert out.closed? assert_match(/^X-Whatever: stuff\r\nX-Whatever: bleh\r\n/, out.string) end @@ -68,7 +69,7 @@ class ResponseTest < Test::Unit::TestCase # some broken clients still rely on it def test_status_header_added out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, []]) + http_response_write(out,[200, {"X-Whatever" => "stuff"}, []]) assert out.closed? assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/i).size end @@ -79,7 +80,7 @@ class ResponseTest < Test::Unit::TestCase def test_status_header_ignores_app_hash out = StringIO.new header_hash = {"X-Whatever" => "stuff", 'StaTus' => "666" } - HttpResponse.write(out,[200, header_hash, []]) + http_response_write(out,[200, header_hash, []]) assert out.closed? assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/i).size assert_equal 1, out.string.split(/\r\n/).grep(/^Status:/i).size @@ -90,7 +91,7 @@ class ResponseTest < Test::Unit::TestCase body = StringIO.new(expect_body) body.rewind out = StringIO.new - HttpResponse.write(out,[200, {}, body]) + http_response_write(out,[200, {}, body]) assert out.closed? assert body.closed? assert_match(expect_body, out.string.split(/\r\n/).last) @@ -98,7 +99,7 @@ class ResponseTest < Test::Unit::TestCase def test_unknown_status_pass_through out = StringIO.new - HttpResponse.write(out,["666 I AM THE BEAST", {}, [] ]) + http_response_write(out,["666 I AM THE BEAST", {}, [] ]) assert out.closed? headers = out.string.split(/\r\n\r\n/).first.split(/\r\n/) assert %r{\AHTTP/\d\.\d 666 I AM THE BEAST\z}.match(headers[0]) -- cgit v1.2.3-24-ge0c7