Instiki 0.16.3: Rails 2.3.0

Instiki now runs on the Rails 2.3.0 Candidate Release.
Among other improvements, this means that it now 
automagically selects between WEBrick and Mongrel.

Just run

    ./instiki --daemon
This commit is contained in:
Jacques Distler 2009-02-04 14:26:08 -06:00
parent 43aadecc99
commit 4e14ccc74d
893 changed files with 71965 additions and 28511 deletions

View file

@ -0,0 +1,57 @@
module Rack
module Handler
class CGI
def self.run(app, options=nil)
serve app
end
def self.serve(app)
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env.update({"rack.version" => [0,1],
"rack.input" => STDIN,
"rack.errors" => STDERR,
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => true,
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
status, headers, body = app.call(env)
begin
send_headers status, headers
send_body body
ensure
body.close if body.respond_to? :close
end
end
def self.send_headers(status, headers)
STDOUT.print "Status: #{status}\r\n"
headers.each { |k, vs|
vs.each { |v|
STDOUT.print "#{k}: #{v}\r\n"
}
}
STDOUT.print "\r\n"
STDOUT.flush
end
def self.send_body(body)
body.each { |part|
STDOUT.print part
STDOUT.flush
}
end
end
end
end

View file

@ -0,0 +1,8 @@
require 'swiftcore/evented_mongrel'
module Rack
module Handler
class EventedMongrel < Handler::Mongrel
end
end
end

View file

@ -0,0 +1,86 @@
require 'fcgi'
require 'socket'
module Rack
module Handler
class FastCGI
def self.run(app, options={})
file = options[:File] and STDIN.reopen(UNIXServer.new(file))
port = options[:Port] and STDIN.reopen(TCPServer.new(port))
FCGI.each { |request|
serve request, app
}
end
module ProperStream # :nodoc:
def each # This is missing by default.
while line = gets
yield line
end
end
def read(*args)
if args.empty?
super || "" # Empty string on EOF.
else
super
end
end
end
def self.serve(request, app)
env = request.env
env.delete "HTTP_CONTENT_LENGTH"
request.in.extend ProperStream
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env.update({"rack.version" => [0,1],
"rack.input" => request.in,
"rack.errors" => request.err,
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => false,
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
})
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
status, headers, body = app.call(env)
begin
send_headers request.out, status, headers
send_body request.out, body
ensure
body.close if body.respond_to? :close
request.finish
end
end
def self.send_headers(out, status, headers)
out.print "Status: #{status}\r\n"
headers.each { |k, vs|
vs.each { |v|
out.print "#{k}: #{v}\r\n"
}
}
out.print "\r\n"
out.flush
end
def self.send_body(out, body)
body.each { |part|
out.print part
out.flush
}
end
end
end
end

View file

@ -0,0 +1,52 @@
require 'lsapi'
#require 'cgi'
module Rack
module Handler
class LSWS
def self.run(app, options=nil)
while LSAPI.accept != nil
serve app
end
end
def self.serve(app)
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env.update({"rack.version" => [0,1],
"rack.input" => STDIN,
"rack.errors" => STDERR,
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => false,
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
status, headers, body = app.call(env)
begin
send_headers status, headers
send_body body
ensure
body.close if body.respond_to? :close
end
end
def self.send_headers(status, headers)
print "Status: #{status}\r\n"
headers.each { |k, vs|
vs.each { |v|
print "#{k}: #{v}\r\n"
}
}
print "\r\n"
STDOUT.flush
end
def self.send_body(body)
body.each { |part|
print part
STDOUT.flush
}
end
end
end
end

View file

@ -0,0 +1,82 @@
require 'mongrel'
require 'stringio'
module Rack
module Handler
class Mongrel < ::Mongrel::HttpHandler
def self.run(app, options={})
server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
options[:Port] || 8080)
# Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
# Use is similar to #run, replacing the app argument with a hash of
# { path=>app, ... } or an instance of Rack::URLMap.
if options[:map]
if app.is_a? Hash
app.each do |path, appl|
path = '/'+path unless path[0] == ?/
server.register(path, Rack::Handler::Mongrel.new(appl))
end
elsif app.is_a? URLMap
app.instance_variable_get(:@mapping).each do |(host, path, appl)|
next if !host.nil? && !options[:Host].nil? && options[:Host] != host
path = '/'+path unless path[0] == ?/
server.register(path, Rack::Handler::Mongrel.new(appl))
end
else
raise ArgumentError, "first argument should be a Hash or URLMap"
end
else
server.register('/', Rack::Handler::Mongrel.new(app))
end
yield server if block_given?
server.run.join
end
def initialize(app)
@app = app
end
def process(request, response)
env = {}.replace(request.params)
env.delete "HTTP_CONTENT_TYPE"
env.delete "HTTP_CONTENT_LENGTH"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env.update({"rack.version" => [0,1],
"rack.input" => request.body || StringIO.new(""),
"rack.errors" => STDERR,
"rack.multithread" => true,
"rack.multiprocess" => false, # ???
"rack.run_once" => false,
"rack.url_scheme" => "http",
})
env["QUERY_STRING"] ||= ""
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
status, headers, body = @app.call(env)
begin
response.status = status.to_i
response.send_status(nil)
headers.each { |k, vs|
vs.each { |v|
response.header[k] = v
}
}
response.send_header
body.each { |part|
response.write part
response.socket.flush
}
ensure
body.close if body.respond_to? :close
end
end
end
end
end

View file

@ -0,0 +1,57 @@
require 'scgi'
require 'stringio'
module Rack
module Handler
class SCGI < ::SCGI::Processor
attr_accessor :app
def self.run(app, options=nil)
new(options.merge(:app=>app,
:host=>options[:Host],
:port=>options[:Port],
:socket=>options[:Socket])).listen
end
def initialize(settings = {})
@app = settings[:app]
@log = Object.new
def @log.info(*args); end
def @log.error(*args); end
super(settings)
end
def process_request(request, input_body, socket)
env = {}.replace(request)
env.delete "HTTP_CONTENT_TYPE"
env.delete "HTTP_CONTENT_LENGTH"
env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["PATH_INFO"] = env["REQUEST_PATH"]
env["QUERY_STRING"] ||= ""
env["SCRIPT_NAME"] = ""
env.update({"rack.version" => [0,1],
"rack.input" => StringIO.new(input_body),
"rack.errors" => STDERR,
"rack.multithread" => true,
"rack.multiprocess" => true,
"rack.run_once" => false,
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
})
status, headers, body = app.call(env)
begin
socket.write("Status: #{status}\r\n")
headers.each do |k, vs|
vs.each {|v| socket.write("#{k}: #{v}\r\n")}
end
socket.write("\r\n")
body.each {|s| socket.write(s)}
ensure
body.close if body.respond_to? :close
end
end
end
end
end

View file

@ -0,0 +1,8 @@
require 'swiftcore/swiftiplied_mongrel'
module Rack
module Handler
class SwiftipliedMongrel < Handler::Mongrel
end
end
end

View file

@ -0,0 +1,15 @@
require "thin"
module Rack
module Handler
class Thin
def self.run(app, options={})
server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
options[:Port] || 8080,
app)
yield server if block_given?
server.start
end
end
end
end

View file

@ -0,0 +1,62 @@
require 'webrick'
require 'stringio'
module Rack
module Handler
class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
def self.run(app, options={})
server = ::WEBrick::HTTPServer.new(options)
server.mount "/", Rack::Handler::WEBrick, app
trap(:INT) { server.shutdown }
trap('TERM') { server.shutdown }
yield server if block_given?
server.start
end
def initialize(server, app)
super server
@app = app
end
def service(req, res)
env = req.meta_vars
env.delete_if { |k, v| v.nil? }
env.update({"rack.version" => [0,1],
"rack.input" => StringIO.new(req.body.to_s),
"rack.errors" => STDERR,
"rack.multithread" => true,
"rack.multiprocess" => false,
"rack.run_once" => false,
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["QUERY_STRING"] ||= ""
env["REQUEST_PATH"] ||= "/"
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
status, headers, body = @app.call(env)
begin
res.status = status.to_i
headers.each { |k, vs|
if k.downcase == "set-cookie"
res.cookies.concat vs.to_a
else
vs.each { |v|
res[k] = v
}
end
}
body.each { |part|
res.body << part
}
ensure
body.close if body.respond_to? :close
end
end
end
end
end