Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/evma_httpserver/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions test/test_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down