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-02-08 12:48:41 +00:00
|
|
|
if ARGV.length != 3
|
|
|
|
STDERR.puts "usage: simpletest.rb <host> <port> <docroot>"
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2006-02-21 00:55:39 +00:00
|
|
|
h = Mongrel::HttpServer.new(ARGV[0], ARGV[1].to_i)
|
2006-02-08 12:48:41 +00:00
|
|
|
h.register("/", SimpleHandler.new)
|
|
|
|
h.register("/files", Mongrel::DirHandler.new(ARGV[2]))
|
|
|
|
h.run
|
|
|
|
|
2006-02-20 22:39:37 +00:00
|
|
|
trap("INT") { h.stop }
|
|
|
|
|
2006-02-08 12:48:41 +00:00
|
|
|
puts "Mongrel running on #{ARGV[0]}:#{ARGV[1]} with docroot #{ARGV[2]}"
|
2006-01-28 19:03:53 +00:00
|
|
|
|
2006-02-08 12:48:41 +00:00
|
|
|
h.acceptor.join
|