1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Implemented access to the RailsHandler from inside rails. Closed off the remaining bugs on our tracker.

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@74 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
zedshaw 2006-03-04 17:55:39 +00:00
parent ec5d3f2b6c
commit d150cae477
5 changed files with 29 additions and 8 deletions

View file

@ -30,7 +30,7 @@ end
setup_extension("http11", "http11")
version="0.3.7"
version="0.3.7.1"
summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
test_file = "test/test_ws.rb"
author="Zed A. Shaw"

View file

@ -20,7 +20,7 @@ module GenericCommand
def validate
valid? @svc_name != nil, "You must specify the service name to be uninstalled."
# We should validate service existance here, right Zed?
# Validate that the service exists
begin
valid? Service.exists?(@svc_name), "There is no service with that name, cannot proceed."
rescue

View file

@ -140,7 +140,7 @@ module Mongrel
SERVER_SOFTWARE='SERVER_SOFTWARE'
# Current Mongrel version (used for SERVER_SOFTWARE and other response headers).
MONGREL_VERSION='Mongrel 0.3.7'
MONGREL_VERSION='Mongrel 0.3.8'
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"
@ -445,6 +445,8 @@ module Mongrel
end
@acceptor.priority = 1
return @acceptor
end

View file

@ -1,14 +1,28 @@
require 'cgi'
module Mongrel
# The beginning of a complete wrapper around Mongrel's internal HTTP processing
# The beginning of a complete wrapper around Mongrel's internal HTTP processing
# system but maintaining the original Ruby CGI module. Use this only as a crutch
# to get existing CGI based systems working. It should handle everything, but please
# notify me if you see special warnings. This work is still very alpha so I need
# testers to help work out the various corner cases.
#
# The CGIWrapper.handler attribute is normally not set and is available for
# frameworks that need to get back to the handler. Rails uses this to give
# people access to the RailsHandler#files (DirHandler really) so they can
# look-up paths and do other things withthe files managed there.
#
# In Rails you can get the real file for a request with:
#
# path = @request.cgi.handler.files.can_serve(@request['PATH_INFO'])
#
# Which is ugly but does the job. Feel free to write a Rails helper for that.
# Refer to DirHandler#can_serve for more information on this.
class CGIWrapper < ::CGI
public :env_table
attr_reader :options
attr_reader :handler
attr_writer :handler
# these are stripped out of any keys passed to CGIWrapper.header function
REMOVED_KEYS = [ "nph","status","server","connection","type",
@ -143,5 +157,6 @@ module Mongrel
STDERR.puts "WARNING: Your program is doing something not expected. Please tell Zed that stdoutput was used and what software you are running. Thanks."
@response.body
end
end
end

View file

@ -19,7 +19,11 @@ require 'mongrel'
#
# This means that if you are using page caching it will actually work with Mongrel
# and you should see a decent speed boost (but not as fast as if you use lighttpd).
#
# An additional feature you can use is
class RailsHandler < Mongrel::HttpHandler
attr_reader :files
def initialize(dir, mime_map = {})
@files = Mongrel::DirHandler.new(dir,false)
@guard = Mutex.new
@ -37,19 +41,19 @@ class RailsHandler < Mongrel::HttpHandler
def process(request, response)
return if response.socket.closed?
path_info = request.params["PATH_INFO"]
page_cached = request.params["PATH_INFO"] + ".html"
path_info = request.params[Mongrel::Const::PATH_INFO]
page_cached = request.params[Mongrel::Const::PATH_INFO] + ".html"
if @files.can_serve(path_info)
# File exists as-is so serve it up
@files.process(request,response)
elsif @files.can_serve(page_cached)
# possible cached page, serve it up
request.params["PATH_INFO"] = page_cached
request.params[Mongrel::Const::PATH_INFO] = page_cached
@files.process(request,response)
else
cgi = Mongrel::CGIWrapper.new(request, response)
cgi.handler = self
begin
@guard.synchronize do
# Rails is not thread safe so must be run entirely within synchronize