[Mongrel] order of registering uri's matters for URIClassifier ?

Jeremy Hinegardner jeremy at hinegardner.org
Fri Apr 20 04:15:02 EDT 2007

Hi all,

I'm playing around with mongrel handlers and I came across a behaviour
that seems abnormal to me with regard to the Configurator#uri calls.  It
appears that order matters.

For instance:

    listener do 
        uri "/icons", :handler => DirHandler.new("/var/www/icons")
        uri "/", :handler => DirHandler.new("/var/app/html")
        uri "/", :handler => stats

with this sort of configuration, any URI that is alphabetically AFTER
"/icons" will be short circuited to a 404 error in mongrel.

The cause is basically :
    @classifier.resolve("/junk")  # => [nil,nil,nil]

Instead of :
    ["/junk", "/", [#<Mongrel::DirHandler>, #<Mongrel::StatusHandler>]]

I've attached a unit test that shows this effect by calling the
URIClassifier directly.  I'm not sure if this is a bug or a
misunderstanding on my part.



 Jeremy Hinegardner                              jeremy at hinegardner.org 

-------------- next part --------------
require 'test/unit'
require 'rubygems'
require 'mongrel'

include Mongrel 
class URIClassifierText < Test::Unit::TestCase
    def test_classifier_order
        u = URIClassifier.new
        root = "/"
        path = "/path"


        ["/before", "/way_past"].each do |uri|
            sn,pi,h = u.resolve(uri)
            assert_equal root,sn
            assert_equal uri, pi
            assert_equal 2,h

More information about the Mongrel-users mailing list