In message <32734.167.203.48.180.1100893533.squirrel@167.203.48.180>,
`"Lloyd Zusman" <ljz@asfast.com>' wrote:
> I have a mount_proc that handles a range of URL's. After doing
> some initial processing within the mount_proc, I want to pass a
> subset of these URL's to a FileHandler; for the rest of the URL's
> I just want to output a message.
[snip]
> What do I put between the 'if' and the 'else' in order to send the
> matching requests to a FileHandler?
Setup an instance of FileHandler by get_instance() and call
service().
In the following code, the mounted proc maps /icons/*.png
into files under IconDir. FileHandler will return the
content of the file which indicated by IconDir + req.path_info.
require "webrick"
IconDir = File.expand_path("~/public_html/icons")
httpd = WEBrick::HTTPServer.new(:Port => 8080)
httpd.mount_proc("/"){|req, res|
if %r{^(/icons)(/[^/]+.png)$} =~ req.path
req.script_name = $1
req.path_info = $2
klass = WEBrick::HTTPServlet::FileHandler
fh = klass.get_instance(httpd, IconDir)
fh.service(req, res)
else
res.body = 'No FileHandler -- just this simple message'
res['Content-type'] = 'text/plain'
end
}
Signal.trap(:INT){ httpd.shutdown }
httpd.start
hope this helps,
--
gotoyuzo