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. --- lib/unicorn.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 7f91352..2a5f493 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -90,6 +90,7 @@ module Unicorn :reexec_pid, :orig_app, :init_listeners, :master_pid, :config, :ready_pipe, :user) include ::Unicorn::SocketHelper + include ::Unicorn::HttpResponse # prevents IO objects in here from being GC-ed IO_PURGATORY = [] @@ -626,14 +627,16 @@ module Unicorn # in 3 easy steps: read request, call app, write app response def process_client(client) client.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - response = app.call(env = REQUEST.read(client)) + r = app.call(env = REQUEST.read(client)) - if 100 == response[0].to_i + if 100 == r[0].to_i client.write(Const::EXPECT_100_RESPONSE) env.delete(Const::HTTP_EXPECT) - response = app.call(env) + r = app.call(env) end - HttpResponse.write(client, response, HttpRequest::PARSER.headers?) + # r may be frozen or const, so don't modify it + HttpRequest::PARSER.headers? or r = [ r[0], nil, r[2] ] + http_response_write(client, r) rescue => e handle_error(client, e) end -- cgit v1.2.3-24-ge0c7