In message <20031218.192516.24444253.gotoyuzo@kotetsu.does.notwork.org>,
`GOTOU Yuuzou <gotoyuzo@notwork.org>' wrote:
> HTTPServlet::AbstractServlet のように do_XXXX を再定義して使
> うクラスを作ってみましたが、なかなか使いやすそうです。
> # config の引き回し方がちょっとダメな感じですが。
いくつか修正してみました。
http://www.does.notwork.org/~gotoyuzo/tmp/webrick-cgi.rb
あまり難しいことをしなければ、
module MyApp
def do_GET(req, res)
res["content-type"] = "text/plain"
res.body = "Hello, world."
end
end
if $stdin.tty?
require "webrick"
class MyServlet < WEBrick::HTTPServlet::AbstractServlet
include MyApp
end
httpd = WEBrick::HTTPServer.new(:Port => 8080)
httpd.mount("/", MyServlet)
httpd.start
else
class MyCGI < WEBrick::CGI
include MyApp
end
cgi = MyCGI.new()
cgi.start
end
という感じで、ServletとCGIで共通のコードが使えそうです。
--
ごとうゆうぞう