Index: [Article Count Order] [Thread]

Date: Fri, 19 Nov 2004 19:09:26 -0500
From: Lloyd Zusman <ljz@asfast.com>
Subject: [webricken:131] Re: Invoking a FileHandler from a mount_proc?
To: webricken@notwork.org
Cc: gotoyuzo@notwork.org
Message-Id: <m3actd9ya1.wl%ljz@asfast.com>
In-Reply-To: <20041120.075932.635724833.gotoyuzo@sawara.does.notwork.org>
References: <32734.167.203.48.180.1100893533.squirrel@167.203.48.180>	<20041120.075932.635724833.gotoyuzo@sawara.does.notwork.org>
X-Mail-Count: 00131

At Sat, 20 Nov 2004 07:59:32 +0900 (JST),
GOTOU Yuuzou wrote:
> 
> In message <32734.167.203.48.180.1100893533.squirrel@167.203.48.180>,
>  `"Lloyd Zusman" <ljz@asfast.com>' wrote:
> >
> > [ ... ]
> >
> > 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().
>
> [ ... ]
> 
>   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,

This indeed helps!  It's exactly the information that I've been looking
for.  Thank you very much.

-- 
 Lloyd Zusman
 ljz@asfast.com
 God bless you.