diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-08-19 02:03:58 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-08-19 02:03:58 -0700 |
commit | 14d429e43e2aedb2615dcc3b7b013633f9a3b760 (patch) | |
tree | ee8b004bef228ba5b39c3af46e69b051cafa1ede /lib/unicorn/rainbows.rb | |
parent | ef3ce3c839a61acbb6ac0c138e4a90d449163cf8 (diff) | |
download | unicorn-14d429e43e2aedb2615dcc3b7b013633f9a3b760.tar.gz |
keepalive/pipelining absolutely does not make sense with classic Unicorn, but it does make sense when connections are cheap with Revactor. Of course any server that serves multiple clients concurrently within the same process is less robust anyways.
Diffstat (limited to 'lib/unicorn/rainbows.rb')
-rw-r--r-- | lib/unicorn/rainbows.rb | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/unicorn/rainbows.rb b/lib/unicorn/rainbows.rb index 21ec43b..f5f6a17 100644 --- a/lib/unicorn/rainbows.rb +++ b/lib/unicorn/rainbows.rb @@ -12,29 +12,33 @@ module Unicorn "rack.multithread" => true, "SERVER_SOFTWARE" => "Unicorn Rainbows! #{Const::UNICORN_VERSION}", }) - SKIP = HttpResponse::SKIP - CODES = HttpResponse::CODES # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) - env = { Const::REMOTE_ADDR => client.remote_addr } + env = {} + remote_addr = client.remote_addr hp = HttpParser.new buf = client.read - while ! hp.headers(env, buf) - buf << client.read - end - env[Const::RACK_INPUT] = 0 == hp.content_length ? - HttpRequest::NULL_IO : TeeInput.new(client, env, hp, buf) - response = app.call(env.update(DEFAULTS)) + begin + while ! hp.headers(env, buf) + buf << client.read + end + + env[Const::REMOTE_ADDR] = remote_addr + env[Const::RACK_INPUT] = 0 == hp.content_length ? + HttpRequest::NULL_IO : TeeInput.new(client, env, hp, buf) + response = app.call(env.update(DEFAULTS)) - if 100 == response.first.to_i - client.write(Const::EXPECT_100_RESPONSE) - env.delete(Const::HTTP_EXPECT) - response = app.call(env) - end - HttpResponse.write(client, response) + if 100 == response.first.to_i + client.write(Const::EXPECT_100_RESPONSE) + env.delete(Const::HTTP_EXPECT) + response = app.call(env) + end + HttpResponse.write(client, response, hp.keepalive?) + end while hp.keepalive? and hp.reset.nil? and env.clear + client.close # if we get any error, try to write something back to the client # assuming we haven't closed the socket, but don't get hung up # if the socket is already closed or broken. We'll always ensure |