-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* lib/camping/fastcgi.rb: new FastCGI app mounter for running severa…
…l apps in a single process.
- Loading branch information
_why
committed
May 18, 2006
1 parent
3302af5
commit a81c8a0
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'fcgi' | ||
|
||
module Camping | ||
class FastCGI | ||
def initialize | ||
@mounts = {} | ||
end | ||
def mount(dir, app) | ||
dir.gsub!(/\/{2,}/, '/') | ||
dir.gsub!(/\/+$/, '') | ||
@mounts[dir] = app | ||
end | ||
def match(path, mount) | ||
m = path.match(/^#{Regexp::quote mount}(\/|$)/) | ||
if m: m.end(0) | ||
else -1 | ||
end | ||
end | ||
def start | ||
FCGI.each do |req| | ||
# req.out << app.run(req.in, req.env) | ||
path = req.env['SCRIPT_NAME'] + req.env['PATH_INFO'] | ||
dir, app = @mounts.max { |a,b| match(path, a[0]) <=> match(path, b[0]) } | ||
req.env['SCRIPT_NAME'] = dir | ||
req.env['PATH_INFO'] = path.gsub(/^#{dir}/, '') | ||
req.out << app.run(req.in, req.env) | ||
req.finish | ||
end | ||
end | ||
def self.start(app) | ||
cf = Camping::FastCGI.new | ||
cf.mount("/", app) | ||
cf.start | ||
end | ||
end | ||
end |