From a4a3fbb761e5ae4f36e9dd84ad933c6df63975ba Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 21 Jun 2010 05:48:45 +0000 Subject: dev_fd_response: cleanup and reorganization There's no need to #dup the middleware object, just use a custom Rainbows::DevFdResponse::Body object. --- lib/rainbows/dev_fd_response.rb | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'lib/rainbows/dev_fd_response.rb') 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 -- cgit v1.2.3-24-ge0c7