From: Eric Hodel Date: 2003-10-22T13:25:09-07:00 Subject: Re: Webrick for IOWA? --UK1lfQXsnwKrySH9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Kirk Haines (khaines@enigo.com) wrote: > IOWA's basic architecture has the IOWA application running as a standalone > process. When the webserver receives a request that is to be handled by > the IOWA application, a connection is made to the IOWA process via either > a CGI program or (currently) a mod_ruby handler. The request is > encapsulated in a serialized object that looks and acts a lot like an > Apache::Request. The IOWA app does its thing, and returns back to its > caller (the cgi program or mod_ruby handler) the Apache::Request with http > headers and content, ready to push on back out to the browser. > Since webrick is now a standard component of Ruby, what I am wondering, > really, is exactly what webrick provides? Would it be > worthwhile/practical for me to look at changing IOWA so that webrick > provides the framework for the communications conduit? Webrick provides servlet stubs and everything else, so it would be practical, probably trivial, to port IOWA to it. Here's what I use for Borges, all the work happens in do_GET/do_POST, and the majority of that work is simply mapping WEBrick Request/Response to a Borges request/response. (With a little work, I may be able to use a webrick request/response inside Borges, I haven't looked into it yet.) require 'webrick' class BorgesServer < WEBrick::HTTPServlet::AbstractServlet attr_accessor :handler=20 def initialize(server, options =3D {}) super @handler =3D options[:Handler] || WADispatcher.default end ## # WEBrick HTTP GET handler=20 def do_GET(req, res) request =3D WARequest.new(req.path, req.header, req.query, req.cookies) response =3D @handler.handle_request(request) res.status =3D response.status res.body =3D response.contents response.headers.each do |k,v| res[k] =3D v=20 end end ## # WEBrick HTTP POST handler (same as GET) alias do_POST do_GET ## # Create a new Borges Server=20 def self.create(options) options[:BindAddress] ||=3D '0.0.0.0' options[:Listen] ||=3D [['::', 7000]] options[:Port] ||=3D 7000 server =3D WEBrick::HTTPServer.new(options) server.mount("/borges", BorgesServer, options) return server=20 end ## # Start a new BorgesServer with a SIGINT handler=20 def self.start(options =3D {}) server =3D self.create(options) trap("INT") do server.shutdown end server.start return server=20 end end --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --UK1lfQXsnwKrySH9 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/luelMypVHHlsnwQRAviYAJ4oDWLc+gKBv+aLgQC/15GZCM7c2ACgoBzY XY9RRk9P6wpGGea2k6OpTh0= =pAaW -----END PGP SIGNATURE----- --UK1lfQXsnwKrySH9--