From: Eric Hodel Date: 2004-05-24T13:34:01-07:00 Subject: Re: Webrick & HOWTO type docs? --orO6xySwJI16pVnm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Kirk Haines (khaines@enigo.com) wrote: > I think I know the answer to this already, but.... >=20 > Are there any not-so-easy-to-find documents anywhere on using Webrick? A= PI=20 > docs or howto docs or anything like that? >=20 > I'm going to make Iowa capable of using webrick so that an Iowa applicati= on=20 > can be a completely standalone application server. From what I can tell,= =20 > this graft looks like it should be an extremely simple one, but I haven't= =20 > been able to find a lot of documentation so I'm mostly going to be workin= g=20 > from looking at the webrick code and at other pieces of software that use= =20 > it, unless someone can point me to something that I have missed. >=20 > If there is nothing, then I will try to document what I learn while I go= =20 > about this project as a way to start making some practical HOWTO type=20 > documentation available for webrick. I haven't found any, but the Servlets provided with WEBrick are a good start. Here's a template: class MyServlet < WEBrick::HTTPServlet::AbstractServlet ## # your_arguments stands in for any extra arguments # # Of course, you may omit #initialize if you don't use extra args def initialize(server, your_arguments) super # setup from your_arguments end ## # HTTP method handlers are prefixed with do_ def do_GET(request, response) status, headers, body =3D do_stuff_with(request) response.status =3D status response.headers =3D headers response.body =3D body end alias do_POST do_GET end To mount the servlet: server =3D WEBrick::HTTPServer.new server.mount "/some/path", MyServlet, any_extra_args Any arguments after the servlet class get passed to the servlet's #new method. Here's the one I use for Borges: http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/borges/lib/Borges/WEBr= ick.rb?rev=3D1.13&cvsroot=3Dborges&content-type=3Dtext/vnd.viewcvs-markup >=20 >=20 > Thanks, >=20 > Kirk Haines >=20 --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --orO6xySwJI16pVnm Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFAslw5MypVHHlsnwQRArH1AJ9zcBk0y6ZX1bgI1scygEcMTaT3LgCg8/X+ D/8uHzntWtJrILXN8L1TQwU= =pt0J -----END PGP SIGNATURE----- --orO6xySwJI16pVnm--