2006-05-23 02:40:24 -04:00
|
|
|
$LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
|
2006-01-28 14:03:53 -05:00
|
|
|
require 'mongrel'
|
|
|
|
require 'yaml'
|
2006-02-11 20:30:33 -05:00
|
|
|
require 'zlib'
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
class SimpleHandler < Mongrel::HttpHandler
|
2006-05-23 02:40:24 -04:00
|
|
|
def process(request, response)
|
|
|
|
response.start do |head,out|
|
|
|
|
head["Content-Type"] = "text/html"
|
|
|
|
results = "<html><body>Your request:<br /><pre>#{request.params.to_yaml}</pre><a href=\"/files\">View the files.</a></body></html>"
|
|
|
|
out << results
|
2006-01-28 14:03:53 -05:00
|
|
|
end
|
2006-05-23 02:40:24 -04:00
|
|
|
end
|
2006-01-28 14:03:53 -05:00
|
|
|
end
|
|
|
|
|
2006-03-19 00:18:11 -05:00
|
|
|
class DumbHandler < Mongrel::HttpHandler
|
|
|
|
def process(request, response)
|
|
|
|
response.start do |head,out|
|
|
|
|
head["Content-Type"] = "text/html"
|
|
|
|
out.write("test")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-02-08 07:48:41 -05:00
|
|
|
if ARGV.length != 3
|
|
|
|
STDERR.puts "usage: simpletest.rb <host> <port> <docroot>"
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2006-03-21 21:17:44 -05:00
|
|
|
config = Mongrel::Configurator.new :host => ARGV[0], :port => ARGV[1] do
|
|
|
|
listener do
|
|
|
|
uri "/", :handler => SimpleHandler.new
|
2006-05-23 02:40:24 -04:00
|
|
|
uri "/", :handler => Mongrel::DeflateFilter.new
|
2006-03-21 21:17:44 -05:00
|
|
|
uri "/dumb", :handler => DumbHandler.new
|
2006-05-23 02:40:24 -04:00
|
|
|
uri "/dumb", :handler => Mongrel::DeflateFilter.new
|
2006-03-21 21:17:44 -05:00
|
|
|
uri "/files", :handler => Mongrel::DirHandler.new(ARGV[2])
|
|
|
|
end
|
2006-02-08 07:48:41 -05:00
|
|
|
|
2006-03-21 21:17:44 -05:00
|
|
|
trap("INT") { stop }
|
|
|
|
run
|
|
|
|
end
|
2006-02-20 17:39:37 -05:00
|
|
|
|
2006-02-08 07:48:41 -05:00
|
|
|
puts "Mongrel running on #{ARGV[0]}:#{ARGV[1]} with docroot #{ARGV[2]}"
|
2006-03-21 21:17:44 -05:00
|
|
|
config.join
|