about summary refs log tree commit homepage
path: root/lib/rainbows/ev_core.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-01-05 18:01:36 -0800
committerEric Wong <normalperson@yhbt.net>2011-01-06 19:50:34 -0800
commit370fb8c7811704ed65384f599b52ac1b6d0c36c9 (patch)
treeff5024a3d1f507c6e88801f0c8f0c6e154bfe1e2 /lib/rainbows/ev_core.rb
parent2cb26ba8084cd37996330616b885de1c780d848e (diff)
downloadrainbows-370fb8c7811704ed65384f599b52ac1b6d0c36c9.tar.gz
async.callback will be useful with Coolio (and more!) soon, so
ensure it works as well as the rest of Rainbows!
Diffstat (limited to 'lib/rainbows/ev_core.rb')
-rw-r--r--lib/rainbows/ev_core.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb
index 013df39..23505d3 100644
--- a/lib/rainbows/ev_core.rb
+++ b/lib/rainbows/ev_core.rb
@@ -13,7 +13,15 @@ module Rainbows::EvCore
 
   def write_async_response(response)
     status, headers, body = response
-    write_response(status, headers, body, false)
+    if alive = @hp.next?
+      # we can't do HTTP keepalive without Content-Length or
+      # "Transfer-Encoding: chunked", and the async.callback stuff
+      # isn't Rack::Lint-compatible, so we have to enforce it here.
+      headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers
+      alive = headers.include?("Content-Length") ||
+              !!(%r{\Achunked\z}i =~ headers["Transfer-Encoding"])
+    end
+    write_response(status, headers, body, alive)
   end
 
   ASYNC_CLOSE = "async.close".freeze