2006-01-28 19:03:53 +00:00
|
|
|
require 'mongrel'
|
|
|
|
require 'yaml'
|
2006-02-12 01:30:33 +00:00
|
|
|
require 'zlib'
|
2006-01-28 19:03:53 +00:00
|
|
|
|
|
|
|
class SimpleHandler < Mongrel::HttpHandler
|
|
|
|
def process(request, response)
|
2006-01-28 19:34:12 +00:00
|
|
|
response.start do |head,out|
|
2006-02-08 12:48:41 +00:00
|
|
|
head["Content-Type"] = "text/html"
|
2006-02-12 01:30:33 +00:00
|
|
|
results = "<html><body>Your request:<br /><pre>#{request.params.to_yaml}</pre><a href=\"/files\">View the files.</a></body></html>"
|
2006-02-14 13:13:14 +00:00
|
|
|
if request.params["HTTP_ACCEPT_ENCODING"] == "gzip,deflate"
|
2006-02-12 01:30:33 +00:00
|
|
|
head["Content-Encoding"] = "deflate"
|
|
|
|
# send it back deflated
|
|
|
|
out << Zlib::Deflate.deflate(results)
|
|
|
|
else
|
|
|
|
# no gzip supported, send it back normal
|
|
|
|
out << results
|
|
|
|
end
|
2006-01-28 19:34:12 +00:00
|
|
|
end
|
2006-01-28 19:03:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-03-19 05:18:11 +00: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 12:48:41 +00:00
|
|
|
if ARGV.length != 3
|
|
|
|
STDERR.puts "usage: simpletest.rb <host> <port> <docroot>"
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2006-03-22 02:17:44 +00:00
|
|
|
config = Mongrel::Configurator.new :host => ARGV[0], :port => ARGV[1] do
|
|
|
|
listener do
|
|
|
|
uri "/", :handler => SimpleHandler.new
|
|
|
|
uri "/dumb", :handler => DumbHandler.new
|
|
|
|
uri "/files", :handler => Mongrel::DirHandler.new(ARGV[2])
|
|
|
|
end
|
2006-02-08 12:48:41 +00:00
|
|
|
|
2006-03-22 02:17:44 +00:00
|
|
|
trap("INT") { stop }
|
|
|
|
run
|
|
|
|
end
|
2006-02-20 22:39:37 +00:00
|
|
|
|
2006-02-08 12:48:41 +00:00
|
|
|
puts "Mongrel running on #{ARGV[0]}:#{ARGV[1]} with docroot #{ARGV[2]}"
|
2006-03-22 02:17:44 +00:00
|
|
|
config.join
|