From 5ec57e5f5d7df07f563722a12d95845579e86e13 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Jul 2010 10:09:48 +0000 Subject: refactor response handling for each concurrency model This will give each concurrency model more control over particular code paths and serving static files. --- lib/rainbows/base.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/rainbows/base.rb') diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index 3fb5a94..d9f46f7 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -52,7 +52,6 @@ module Rainbows::Base buf = client.readpartial(CHUNK_SIZE) # accept filters protect us here hp = HttpParser.new env = {} - alive = true remote_addr = Rainbows.addr(client) begin # loop @@ -65,18 +64,22 @@ module Rainbows::Base env[RACK_INPUT] = 0 == hp.content_length ? NULL_IO : TeeInput.new(client, env, hp, buf) env[REMOTE_ADDR] = remote_addr - response = app.call(env.update(RACK_DEFAULTS)) + status, headers, body = app.call(env.update(RACK_DEFAULTS)) - if 100 == response[0].to_i + if 100 == status.to_i client.write(EXPECT_100_RESPONSE) env.delete(HTTP_EXPECT) - response = app.call(env) + status, headers, body = app.call(env) end - alive = hp.keepalive? && G.alive - out = [ alive ? CONN_ALIVE : CONN_CLOSE ] if hp.headers? - write_response(client, response, out) - end while alive and hp.reset.nil? and env.clear + if hp.headers? + headers = HH.new(headers) + env = false unless hp.keepalive? && G.alive + headers[CONNECTION] = env ? KEEP_ALIVE : CLOSE + client.write(response_header(status, headers)) + end + write_body(client, body) + end while env && env.clear && hp.reset.nil? # 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 -- cgit v1.2.3-24-ge0c7