about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-02-10 01:06:55 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-02-10 01:06:55 +0000
commit3c343cca6b736e43c6145ebdf60aed2cd61b912c (patch)
tree9c61e2dbd6b17b9066b3bce54cfd5bd600508b48
parentda7ed29332ec86f9dc427c0c784f68c34d2ca7e2 (diff)
downloadunicorn-3c343cca6b736e43c6145ebdf60aed2cd61b912c.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@23 19e92222-5c0b-0410-8929-a290d50e31e9
-rw-r--r--bin/mongrel_rails89
-rw-r--r--examples/mongrel_rails.rb85
-rw-r--r--lib/mongrel.rb4
3 files changed, 91 insertions, 87 deletions
diff --git a/bin/mongrel_rails b/bin/mongrel_rails
new file mode 100644
index 0000000..3f7b124
--- /dev/null
+++ b/bin/mongrel_rails
@@ -0,0 +1,89 @@
+require 'config/environment'
+require 'mongrel'
+require 'cgi'
+begin
+  require 'daemons/daemonize'
+  HAVE_DAEMONS=true
+rescue
+  HAVE_DAEMONS=false
+end
+
+
+class CGIFixed < ::CGI
+  public :env_table
+  
+  def initialize(params, data, out, *args)
+    @env_table = params
+    @args = *args
+    @input = StringIO.new(data)
+    @out = out
+    super(*args)
+  end
+  
+  def args
+    @args
+  end
+  
+  def env_table
+    @env_table
+  end
+  
+  def stdinput
+    @input
+  end
+  
+  def stdoutput
+    @out
+  end
+end
+
+
+class RailsHandler < Mongrel::HttpHandler
+  def initialize(dir)
+    @files = Mongrel::DirHandler.new(dir,false)
+    @guard = Mutex.new
+  end
+  
+  def process(request, response)
+    # not static, need to talk to rails
+    return if response.socket.closed?
+    
+    if @files.can_serve(request.params["PATH_INFO"])
+      @files.process(request,response)
+    else
+      cgi = CGIFixed.new(request.params, request.body, response.socket)
+      begin
+        
+        @guard.synchronize do
+          # Rails is not thread safe so must be run entirely within synchronize
+          Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
+        end
+        
+        response.send_status
+        response.send_body
+      rescue IOError
+        @log.error("received IOError #$! when handling client.  Your web server doesn't like me.")
+      rescue Object => rails_error
+        @log.error("calling Dispatcher.dispatch", rails_error)
+      end
+    end
+  end
+end
+
+
+if ARGV.length != 2
+  STDERR.puts "usage:  mongrel_rails <host> <port>"
+  exit(1)
+end
+
+cwd = Dir.pwd
+
+#Daemonize.daemonize(log_file=File.join(cwd,"log","mongrel.log"))
+#Dir.chdir(cwd)
+
+open(File.join(cwd,"log/mongrel-#{ARGV[1]}.pid"),"w") {|f| f.write(Process.pid) }
+h = Mongrel::HttpServer.new(ARGV[0], ARGV[1])
+h.register("/", RailsHandler.new(File.join(cwd,"public")))
+h.run
+
+h.acceptor.join
diff --git a/examples/mongrel_rails.rb b/examples/mongrel_rails.rb
deleted file mode 100644
index b6bce98..0000000
--- a/examples/mongrel_rails.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-require 'config/environment'
-require 'mongrel'
-require 'cgi'
-
-begin
-  require 'daemons/deamonize'
-  HAVE_DAEMONS=true
-rescue
-  HAVE_DAEMONS=false
-end
-
-
-class CGIFixed < ::CGI
-  public :env_table
-  
-  def initialize(params, data, out, *args)
-    @env_table = params
-    @args = *args
-    @input = StringIO.new(data)
-    @out = out
-    super(*args)
-  end
-  
-  def args
-    @args
-  end
-  
-  def env_table
-    @env_table
-  end
-  
-  def stdinput
-    @input
-  end
-  
-  def stdoutput
-    @out
-  end
-end
-
-
-class RailsHandler < Mongrel::HttpHandler
-  def initialize
-    @guard = Mutex.new
-  end
-  
-  def process(request, response)
-    # not static, need to talk to rails
-    return if response.socket.closed?
-    
-    cgi = CGIFixed.new(request.params, request.body, response.socket)
-    begin
-
-      @guard.synchronize do
-        # Rails is not thread safe so must be run entirely within synchronize
-        Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
-      end
-
-      response.send_status
-      response.send_body
-    rescue IOError
-      @log.error("received IOError #$! when handling client.  Your web server doesn't like me.")
-    rescue Object => rails_error
-      @log.error("calling Dispatcher.dispatch", rails_error)
-    end
-  end
-end
-
-if ARGV.length != 2
-  STDERR.puts "usage:  mongrel_rails <host> <port>"
-  exit(1)
-end
-
-h = Mongrel::HttpServer.new(ARGV[0], ARGV[1])
-h.register("/", Mongrel::DirHandler.new(ARGV[2]))
-h.register("/app", RailsHandler.new)
-h.run
-
-h.acceptor.join
-cwd = Dir.pwd
-
-Deamonize.daemonize(log_file=File.join(cwd,"log","mongrel.log")
-open("#{cwd}/log/mongrel-#{Process.pid}.pid","w") {|f| f.write(Process.pid) }
-
-g
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 1bc1c23..d8e1b23 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -452,9 +452,9 @@ module Mongrel
     # Checks if the given path can be served and returns the full path (or nil if not).
     def can_serve(path_info)
       req = File.expand_path(path_info, @path)
-      if req.index(@path) != 0 or !File.exist? req
+      if req.index(@path) != 0 or !File.exist? req or (File.directory?(req) and not @listing_allowed)
         return nil
-      else
+       else
         return req
       end
     end