about summary refs log tree commit homepage
path: root/lib/rainbows/response.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-22 05:42:16 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-22 09:09:37 +0000
commit416d3a0f868571319a2b29b0034d2dba68e4d5b3 (patch)
tree081bdbdcce23063667c707212ceda45bbc322675 /lib/rainbows/response.rb
parent015daa81f26afc59d1da857b8bbedfb80eb532b1 (diff)
downloadrainbows-416d3a0f868571319a2b29b0034d2dba68e4d5b3.tar.gz
The FileStreamer class of EventMachine (and by extension
NeverBlock) unfortunately doesn't handle this.  It's possible
to do with Revactor (since it uses Rev under the covers),
but we'll support what we can easily for now.
Diffstat (limited to 'lib/rainbows/response.rb')
-rw-r--r--lib/rainbows/response.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb
index 13946ca..44be30f 100644
--- a/lib/rainbows/response.rb
+++ b/lib/rainbows/response.rb
@@ -3,6 +3,8 @@
 require 'time' # for Time#httpdate
 
 module Rainbows::Response
+  autoload :Body, 'rainbows/response/body'
+  autoload :Range, 'rainbows/response/range'
 
   CODES = Unicorn::HttpResponse::CODES
   CRLF = "\r\n"
@@ -32,7 +34,25 @@ module Rainbows::Response
 
   # called after forking
   def self.setup(klass)
-    require('rainbows/response/body') and
-      klass.__send__(:include, Rainbows::Response::Body)
+    range_class = body_class = klass
+    case Rainbows::Const::RACK_DEFAULTS['rainbows.model']
+    when :WriterThreadSpawn
+      body_class = Rainbows::WriterThreadSpawn::MySocket
+      range_class = Rainbows::HttpServer
+    when :EventMachine, :NeverBlock, :Revactor
+      range_class = nil # :<
+    end
+    return if body_class.included_modules.include?(Body)
+    body_class.__send__(:include, Body)
+    sf = IO.respond_to?(:copy_stream) || IO.method_defined?(:sendfile_nonblock)
+    if range_class
+      range_class.__send__(:include, sf ? Range : NoRange)
+    end
+  end
+
+  module NoRange
+    # dummy method if we can't send range responses
+    def parse_range(env, status, headers)
+    end
   end
 end