about summary refs log tree commit homepage
path: root/lib/rainbows/revactor.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-19 10:09:48 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-19 17:04:14 -0700
commit5ec57e5f5d7df07f563722a12d95845579e86e13 (patch)
treec2012a7a968d96786fb15d50185fc11468c92e1f /lib/rainbows/revactor.rb
parent399bbdb5c5e7cf9e716aacd9f0763813edf52423 (diff)
downloadrainbows-5ec57e5f5d7df07f563722a12d95845579e86e13.tar.gz
This will give each concurrency model more control over
particular code paths and serving static files.
Diffstat (limited to 'lib/rainbows/revactor.rb')
-rw-r--r--lib/rainbows/revactor.rb23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index 5a9704d..0120ebe 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -41,7 +41,6 @@ module Rainbows::Revactor
     buf = client.read(*rd_args)
     hp = HttpParser.new
     env = {}
-    alive = true
 
     begin
       buf << client.read(*rd_args) until hp.headers(env, buf)
@@ -50,18 +49,26 @@ module Rainbows::Revactor
       env[RACK_INPUT] = 0 == hp.content_length ?
                NULL_IO : TeeInput.new(PartialSocket.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)
+        headers[CONNECTION] = if hp.keepalive? && G.alive
+          KEEP_ALIVE
+        else
+          env = false
+          CLOSE
+        end
+        client.write(response_header(status, headers))
+      end
+      write_body(client, body)
+    end while env && env.clear && hp.reset.nil?
   rescue ::Revactor::TCP::ReadError
   rescue => e
     Rainbows::Error.write(io, e)