about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-21 05:48:45 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-21 05:48:45 +0000
commita4a3fbb761e5ae4f36e9dd84ad933c6df63975ba (patch)
tree3ad531bb7c7d839e673017a2e1ce7047d5eb5140 /lib
parentf2b75a59b54ec93e7fe0031d79127e2ed960725b (diff)
downloadrainbows-a4a3fbb761e5ae4f36e9dd84ad933c6df63975ba.tar.gz
There's no need to #dup the middleware object, just use
a custom Rainbows::DevFdResponse::Body object.
Diffstat (limited to 'lib')
-rw-r--r--lib/rainbows/dev_fd_response.rb42
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb
index 479a668..0489fd6 100644
--- a/lib/rainbows/dev_fd_response.rb
+++ b/lib/rainbows/dev_fd_response.rb
@@ -9,7 +9,8 @@ module Rainbows
   # on servers that support it to pass arbitrary file descriptors into
   # the HTTP response without additional open(2) syscalls
 
-  class DevFdResponse < Struct.new(:app, :to_io, :to_path)
+  class DevFdResponse < Struct.new(:app)
+    # :stopdoc:
     include Rack::Utils
 
     # Rack middleware entry point, we'll just pass through responses
@@ -45,31 +46,30 @@ module Rainbows
       else # unlikely, char/block device file, directory, ...
         return response
       end
-      resp = dup # be reentrant here
-      resp.to_path = "/dev/fd/#{io.fileno}"
-      resp.to_io = io
-      [ status, headers, resp ]
+      [ status, headers, Body.new(io, "/dev/fd/#{io.fileno}") ]
     end
 
-    # called by the webserver or other middlewares if they can't
-    # handle #to_path
-    def each(&block)
-      to_io.each(&block)
-    end
+    class Body < Struct.new(:to_io, :to_path)
+      # called by the webserver or other middlewares if they can't
+      # handle #to_path
+      def each(&block)
+        to_io.each(&block)
+      end
 
-    # remain Rack::Lint-compatible for people with wonky systems :P
-    unless File.exist?("/dev/fd/0")
-      alias to_path_orig to_path
-      undef_method :to_path
-    end
+      # remain Rack::Lint-compatible for people with wonky systems :P
+      unless File.exist?("/dev/fd/0")
+        alias to_path_orig to_path
+        undef_method :to_path
+      end
 
-    # called by the web server after #each
-    def close
-      begin
-        to_io.close if to_io.respond_to?(:close)
-      rescue IOError # could've been IO::new()'ed and closed
+      # called by the web server after #each
+      def close
+        begin
+          to_io.close if to_io.respond_to?(:close)
+        rescue IOError # could've been IO::new()'ed and closed
+        end
       end
     end
-
+    #:startdoc:
   end # class
 end