diff --git a/lib/evma_httpserver/response.rb b/lib/evma_httpserver/response.rb index 61f7965..09fe032 100644 --- a/lib/evma_httpserver/response.rb +++ b/lib/evma_httpserver/response.rb @@ -98,7 +98,7 @@ def send_response send_headers send_body send_trailer - close_connection_after_writing unless (@keep_connection_open and (@status || 200) == 200) + close_connection_after_writing unless (@keep_connection_open and (@status || 200) < 500) end # Send the headers out in alpha-sorted order. This will degrade performance to some diff --git a/test/test_response.rb b/test/test_response.rb index 5e54c4d..e385479 100644 --- a/test/test_response.rb +++ b/test/test_response.rb @@ -103,6 +103,57 @@ def test_send_response_no_close assert( ! a.closed_after_writing ) end + def test_send_response_no_close_with_a_404_response + a = EventMachine::HttpResponse.new + a.status = 404 + a.content_type "text/plain" + a.content = "ABC" + a.keep_connection_open + a.send_response + assert_equal([ + "HTTP/1.1 404 ...\r\n", + "Content-length: 3\r\n", + "Content-type: text/plain\r\n", + "\r\n", + "ABC" + ].join, a.output_data) + assert( ! a.closed_after_writing ) + end + + def test_send_response_no_close_with_a_201_response + a = EventMachine::HttpResponse.new + a.status = 201 + a.content_type "text/plain" + a.content = "ABC" + a.keep_connection_open + a.send_response + assert_equal([ + "HTTP/1.1 201 ...\r\n", + "Content-length: 3\r\n", + "Content-type: text/plain\r\n", + "\r\n", + "ABC" + ].join, a.output_data) + assert( ! a.closed_after_writing ) + end + + def test_send_response_no_close_with_a_500_response + a = EventMachine::HttpResponse.new + a.status = 500 + a.content_type "text/plain" + a.content = "ABC" + a.keep_connection_open + a.send_response + assert_equal([ + "HTTP/1.1 500 ...\r\n", + "Content-length: 3\r\n", + "Content-type: text/plain\r\n", + "\r\n", + "ABC" + ].join, a.output_data) + assert( a.closed_after_writing ) + end + def test_send_response_multiple_times a = EventMachine::HttpResponse.new a.status = 200