diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:09:48 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:14 -0700 |
commit | 5ec57e5f5d7df07f563722a12d95845579e86e13 (patch) | |
tree | c2012a7a968d96786fb15d50185fc11468c92e1f /lib/rainbows/base.rb | |
parent | 399bbdb5c5e7cf9e716aacd9f0763813edf52423 (diff) | |
download | rainbows-5ec57e5f5d7df07f563722a12d95845579e86e13.tar.gz |
This will give each concurrency model more control over particular code paths and serving static files.
Diffstat (limited to 'lib/rainbows/base.rb')
-rw-r--r-- | lib/rainbows/base.rb | 19 |
1 files changed, 11 insertions, 8 deletions
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 |