#!/usr/local/bin/ruby require "pp" module MyApp def do_GET(req, res) res['content-type'] = 'text/html; charset=iso-8859-1' if req.path_info.nil? or req.path_info.empty? res.set_redirect(WEBrick::HTTPStatus::Found, req.script_name + "/") end res.body =<<-_end_of_html_
#{WEBrick::HTMLUtils::escape(PP::pp(req, "", 80))}
#{WEBrick::HTMLUtils::escape(PP::pp(res, "", 80))}
#{WEBrick::HTMLUtils::escape(PP::pp(self, "", 80))}
_end_of_html_
end
def do_POST(req, res)
res['content-type'] = 'text/html; charset=iso-8859-1'
if req["content-length"].to_i > 1024*10
raise WEBrick::HTTPStatus::Forbidden, "file size too large"
end
res.body =<<-_end_of_html_
#{WEBrick::HTMLUtils::escape(PP::pp(req, "", 80))}
#{WEBrick::HTMLUtils::escape(PP::pp(res, "", 80))}
#{WEBrick::HTMLUtils::escape(PP::pp(self, "", 80))}
_end_of_html_
end
end
if $stdin.tty?
require "webrick"
#require "webrick/https"
class MyServlet < WEBrick::HTTPServlet::AbstractServlet
include MyApp
end
httpd = WEBrick::HTTPServer.new(
:DocumentRoot => File::dirname(File::expand_path(__FILE__)),
:SSLEnable => true,
:SSLCertName => [ [ "CN", "kotetsu.does.notwork.org" ] ],
:Port => 8080
)
httpd.mount("/svr", MyServlet, "option1", "option2")
trap(:INT){ httpd.shutdown }
httpd.start
else
require "webrick/cgi"
#require "webrick/https"
class MyCGI < WEBrick::CGI
include MyApp
end
cgi = MyCGI.new({:Foo=>true}, "option1", "option2")
# cgi = MyCGI.new()
# cgi = MyCGI.new(:Foo=>true)
cgi.start
end