[Nitro] Mysterious behavior when Nitro is given a URL with '.' in it
james_b at neurogami.com
Sun Jan 22 02:34:53 EST 2006
James Britt wrote:
> I think this was discussed here before, but I could not find the thread;
> my apologies if this is rehashing old issues.
Indeed, I see that this is due to the same code that was a problem for
me once before.
> I'm planning on revamping a site and having it run on Nitro. All new
> URLs will (likely) omit file extensions, but I need to handle old links.
> Most of these look like this:
> It seems, though, that any URL with '.' it just causes Nitro to emit a
> blank page.
Various adapters have code such as this:
def handle(req, res)
unless handle_file(req, res)
path = req.request_uri.path
unless path =~ /\./
This is really bad. How, for example, can I create a URL that appears
to refer to an image file (/image/foo.png) but is in fact dynamically
generated or pulled from database? How can I remap old URLs?
This pretty much means you can't have, say:
because Nitro just ignores it.
I changed my version of Nitro to skip this check, and, with casual
clicking around, saw no ill effects. Why not assume that all requests
are Nitro requests and let the Nitro handle it as it sees fit?
Here's a suggestion Ive just tried this out, seems OK, but who knows.
In server.rb, I added another Server setting:
# could use a better name here ...
:default => /\./,
:doc => 'Skip requests where this pattern matches'
In webrick.rb (which I'm currently using for dev) I replaced that
hard-coded regex with this:
# line 131 or so
unless path =~ Nitro::Server.skip_regex
And it seems OK when I add this to run.rb:
Server.skip_regex = /\.gif|\.css/
which allows all sorts of funky URLs to get passed on, where I can route
One new problem, now, is that when handling URLs that end with an
#anchor reference, the anchor name is lost. For example, with
the path_info has '/Nov/26' but nothing in @request seems to have the
complete URL or path or the anchor name ('this_is_some_item' .
More information about the Nitro-general